home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / PC_V11_B.LZH / DEMO_PC / MEMDUMP.C < prev    next >
C/C++ Source or Header  |  1992-07-24  |  2KB  |  122 lines

  1.  
  2. #include <stdio.h>
  3. #include "f:\dspspar\rev21\tsr\dspbind.h"
  4.  
  5. char ch;
  6. long memtype;
  7.  
  8. main()
  9. {
  10.     printf("Simple Dsp Memory Dumper\n");
  11.     printf("For Address: Type P,X, or Y followed by a hex address\n");
  12.     printf("For Count: Type in a Decimal block size to dump out\n");
  13.     printf("\n\n");
  14.     interface();
  15. }
  16.  
  17. send_info(memtype,addr,count)
  18. long memtype;
  19. long addr,count;
  20. {
  21.    addr = addr << 8;
  22.    count = count << 8;
  23.    memtype = memtype << 8;
  24.    Dsp_TriggerHC(0x17);
  25.    Dsp_DoBlock(&memtype,1L,0L,0L);
  26.    Dsp_DoBlock(&addr,1L,0L,0L);
  27.    Dsp_DoBlock(&count,1L,0L,0L);
  28. }
  29.  
  30. long get_data()
  31. {
  32.    long temp;
  33.    Dsp_DoBlock(0L,0L,&temp,1L);
  34.    return(temp);
  35. }
  36.  
  37. interface()
  38. {
  39.     long    addr;
  40.     long    cnt,i,num;
  41.     char    str[6];
  42.     int    cols, maxcols = 8;
  43.  
  44. cnt = 1L;
  45. while(cnt !=0L )
  46. {
  47. /* Get user inputs */
  48.     printf("Address >$");    
  49.     scanf("%c %X",&ch, &addr);
  50.     while(getchar() != '\n');
  51.     printf("Count > ");
  52.     scanf("%D", &cnt);
  53.     while(getchar() != '\n');
  54.     if(ch == 'X' || ch == 'x')
  55.        memtype = 1L;
  56.     else if(ch == 'Y' || ch == 'y')
  57.        memtype = 2L;    
  58.     else
  59.        memtype = 0L;            /* Default p space */
  60.     send_info(memtype,addr,cnt);    
  61.  
  62. /* Convert integer data to string then output only high 24 bits (32-9)  */
  63. /* of long in rows of eight columns.                    */
  64.     cols = 1;
  65.     for (i=0; i<cnt; i++)
  66.     {
  67.         (long)num = get_data();
  68.         word_to_hex( num, str );
  69.         printf("%6s ",str);
  70.  
  71.         if (cols++ == maxcols)
  72.         {
  73.             printf("\n");
  74.             cols = 1;
  75.         }
  76.     }
  77.     printf("\n");
  78. }
  79. }
  80. char
  81. hex_convert( i )
  82. long i;
  83. {
  84.     if ( i < 10 )
  85.     return( i + '0' );
  86.     else
  87.     return( i - 10 + 'A' );
  88. }
  89.  
  90. /* converts a word into ASCII in the form of "0xXXXX" where the X's
  91.  * hex digits.
  92.  */
  93. word_to_hex( num, str )
  94. long num;
  95. char *str;
  96. {
  97.     long i, mask;
  98.  
  99.     str[6] = '\0';
  100.  
  101.     mask = 0x00000F00;
  102.     i = num & mask;
  103.     str[5] = hex_convert( (i >> 8) & 0x0000000F );
  104.     mask = 0x0000F000;
  105.     i = num & mask;
  106.     str[4] = hex_convert( (i >> 12) & 0x0000000F );
  107.     mask = 0x000F0000;
  108.     i = num & mask;
  109.     str[3] = hex_convert( (i >> 16) & 0x0000000F );
  110.     mask = 0x00F00000;
  111.     i = num & mask;
  112.     str[2] = hex_convert( (i >> 20) & 0x0000000F );
  113.     mask = 0x0F000000;
  114.     i = num & mask;
  115.     str[1] = hex_convert( (i >> 24) & 0x0000000F );
  116.     mask = 0xF0000000;
  117.     i = num & mask;
  118.     str[0] = hex_convert( (i >> 28) & 0x0000000F );
  119.  
  120. }
  121.  
  122.