home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR4 / SNES_GEN.ZIP / TESTCART.C < prev    next >
C/C++ Source or Header  |  1994-01-24  |  2KB  |  135 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3.  
  4. /* 4 megabits */
  5. #define SIZE    524288
  6.  
  7. #define MAXBUF  4096
  8. #define NUMSEGS 8
  9.  
  10. /* use CP=37A for lpt2: */
  11. #define CP      0x3be
  12.  
  13. /* use DP=378 for lpt2: */
  14. #define DP      0x3bc
  15.  
  16. /* use IP=379 for lpt2: */
  17. #define IP      0x3bd
  18.  
  19. #define LA      0xe1
  20. #define MA      0xe2
  21. #define HA      0xe3
  22. #define NOPA    0xe0
  23. #define HI_NYB  0xe0
  24. #define LO_NYB  0xe8
  25. #define DELAY   10
  26.  
  27. void loop();
  28.  
  29. void main(argc, argv)
  30. int argc;
  31. char *argv[];
  32. {
  33.  
  34. unsigned char buffer[256], tmp, testhi, testlo, lo_nyb, hi_nyb;
  35. long int segment, page, byte, total=0;
  36. FILE *fp;
  37.  
  38. if (argc > 3) {
  39.     printf("usage: readcart [filename] [4|8|12 megabits]\n");
  40.     exit(1);
  41. }
  42.  
  43. if (argc == 2) {
  44.     if ((fp = fopen(argv[1], "wb")) == NULL) {
  45.         printf("Error opening file.\n");
  46.         exit(1);
  47.     }
  48. }
  49. else {
  50.     if ((fp = fopen("game.dat", "wb")) == NULL) {
  51.         printf("Error opening file.\n");
  52.         exit(1);
  53.     }
  54. }
  55.  
  56.  
  57.  
  58. printf("\n\t\tGAME MEDIC\n");
  59. printf("\t\t\tby The Silicon Valley Swappe Shoppe \n\n");
  60.  
  61. /* start code */
  62. for (segment=0; segment < NUMSEGS; segment++) {
  63.   outportb (DP, segment);
  64.   loop(DELAY);
  65.   outportb (CP, HA);
  66.   loop(DELAY);
  67.   outportb (CP, NOPA);
  68.   loop(DELAY);
  69.  
  70.   for (page=0; page <= 255 ; page++) {
  71.     outportb (DP, page);
  72.     loop(DELAY);
  73.     outportb (CP, MA);
  74.     loop(DELAY);
  75.     outportb(CP, NOPA);
  76.     loop(DELAY);
  77.  
  78.     for (byte=0; byte <= 255 ; byte++) {
  79.       outportb(DP, byte);
  80.       loop(DELAY);
  81.       outportb(CP, LA);
  82.       loop(DELAY);
  83.       outportb(CP, NOPA);
  84.       loop(DELAY);
  85.  
  86.       tmp = inportb(IP);
  87.       hi_nyb = (tmp ^ 0x80) & 0xf0;
  88.  
  89.       outportb(CP, LO_NYB);
  90.       loop(DELAY);
  91.  
  92.       tmp= inport(IP);
  93.       lo_nyb = (tmp ^ 0x80) & 0xf0;
  94.       lo_nyb = lo_nyb >> 4;
  95.       tmp=lo_nyb | hi_nyb;
  96.  
  97.       buffer[byte]=tmp;
  98.       
  99.       testhi = (total & 0x1ff00) >> 9;
  100.       testlo = (total & 0x1ff) >> 1;
  101.       if ((byte % 2) ==0) { /* upper byte */
  102.     if (tmp !=testhi) 
  103.       printf("\007UPPER BYTE ERROR: Address %8x; got %2x, expected %2x\n", 
  104.           (unsigned long int) total, tmp, testhi);
  105.     }
  106.        else
  107.     if (tmp !=testlo)
  108.       printf ("\007LOWER BYTE ERROR: Address %8x; got %2x, expected %2x\n",
  109.           (unsigned long int) total, tmp, testlo);
  110.  
  111.       total++;
  112.       /*
  113.       printf("%2x ", tmp);
  114.       */
  115.       }
  116.     fwrite(buffer, sizeof(unsigned char), 256, fp);
  117.     printf("Written %8ld bytes\r", total);
  118.     /*
  119.     printf("writing\n");
  120.     */
  121.     }
  122.   }
  123.  
  124. fclose(fp);
  125. }
  126.  
  127. void
  128. loop(x)
  129. int x;
  130. {
  131. int i;
  132.  
  133. for (i=0; i< x; i++);
  134. }
  135.