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

  1. #include <stdio.h>
  2. #include <dos.h>
  3.  
  4.  
  5. /* use CP=37A for lpt2: */
  6. #define CP      0x3be
  7.  
  8. /* use DP=378 for lpt2: */
  9. #define DP      0x3bc
  10.  
  11. /* use IP=379 for lpt2: */
  12. #define IP      0x3bd
  13.  
  14. #define LA      0xe1
  15. #define MA      0xe2
  16. #define HA      0xe3
  17. #define NOPA    0xe0
  18. #define HI_NYB  0xe0
  19. #define LO_NYB  0xe8
  20.  
  21. void readblock();
  22. int blockmatch();
  23.  
  24.  
  25. void main(void)
  26. {
  27.  
  28. unsigned char seg;
  29. unsigned char base[256], block[256];
  30. int byte;
  31. int k;
  32. float megs;
  33.  
  34. printf("\n\t\tSIZE TEST\n");
  35. printf("\t\t\tby The Silicon Valley Swappe Shoppe \n\n");
  36.  
  37. for (byte=0; byte<256; byte++) block[byte]=0;
  38.  
  39. /* start code */
  40.   outportb (DP, 0);
  41.   outportb (CP, HA);
  42.   outportb (CP, NOPA);
  43.  
  44.     outportb (DP, 1);
  45.     outportb (CP, MA);
  46.     outportb (CP, NOPA);
  47.  
  48. readblock(base);
  49.  
  50. for (byte=0;byte < 255; byte++) {
  51.      if ((base[byte] >= 0x20) && (base[byte] <=0x7f)) printf ("%c", base[byte]);
  52.      if (((byte+1) % 32)==0) printf("\n");
  53.      }
  54.  
  55. seg=0;
  56.  
  57. while (blockmatch (base, block) == 0) {
  58.   seg++;
  59.   outportb (DP, seg);
  60.   outportb (CP, HA);
  61.   outportb (CP, NOPA);
  62.   readblock(block);
  63. }
  64. k=seg * 64;
  65. megs = seg / 2.0;
  66. printf ("\nCartridge appears to be %d kbytes (%1.1f Megabits)\n", k, megs);
  67.  
  68. }
  69.  
  70.  
  71.  
  72. void
  73. readblock (block)
  74. unsigned char *block;
  75. {
  76. int byte;
  77. unsigned char tmp, hi_nyb, lo_nyb;
  78.  
  79.     for (byte=0; byte < 256 ; byte++) {
  80.       outportb(DP, byte);
  81.       outportb(CP, LA);
  82.  
  83.       outportb(CP, HI_NYB);
  84.       tmp = inportb(IP);
  85.       hi_nyb = (tmp ^ 0x80) & 0xf0;
  86.  
  87.       outportb(CP, LO_NYB);
  88.  
  89.       tmp= inport(IP);
  90.       lo_nyb = (tmp ^ 0x80) & 0xf0;
  91.       lo_nyb = lo_nyb >> 4;
  92.       tmp=lo_nyb | hi_nyb;
  93.       block[byte]=tmp;
  94.     }
  95. }
  96.  
  97. int
  98. blockmatch(block1, block2)
  99. unsigned char *block1, *block2;
  100. {
  101. int i;
  102.  
  103. for (i=0; i<256; i++)
  104.   if (block1[i] != block2[i]) return (0);
  105. return (1);
  106. }
  107.  
  108.