home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / ansi / avatar1.arj / MEMDISP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-13  |  7.2 KB  |  221 lines

  1. /*****************************************************************************
  2.  
  3.    Program: memdisp.c
  4.    Author: G. Adam Stanislav
  5.    Date started: August 11, 1990
  6.    Date completed:
  7.    Purpose: Read contents of various locations and display them
  8.             using AVATAR console
  9.  
  10.  
  11.    Copyright (C) 1990, G. Adam Stanislav
  12.    AVATAR and AVATAR console are trademarks of G. Adam Stanislav and
  13.    Stanislav Publishing.
  14.  
  15. *****************************************************************************/
  16.  
  17.  
  18. #include <stdio.h>
  19. #include <conio.h>
  20. #include <dos.h>
  21. #include <memory.h>
  22.  
  23. #define locate(Xpos,Ypos) printf("\x16\x08%c%c",Xpos,Ypos)
  24.  
  25. void memdisp(void);
  26. void newsegment(unsigned);
  27. void newoffset(unsigned);
  28. int  usage(void);
  29.  
  30. static char two_strings[] = "%s%s";
  31. static char hello[] = "\x16\x12"    /* ^V ^R = reset the driver */
  32.                       "\x0C"        /* ^L    = clear the screen */
  33.                       "\b\b\bmemdisp.exe: "
  34.                       "Copyright (C) 1990, G. Adam Stanislav.\n";
  35.  
  36. static char beep[]  = "\x16\x13\x10\x9A\x10\x80\x02"
  37.                       "\x16\x13\x04\x10\x80\x04";
  38.  
  39.  
  40. int main(int argc, char *argv[]) {
  41.    register i, ch;
  42.    char buffer[80];
  43.    int  flag = 0;
  44.  
  45.    if (argc > 1) {
  46.       if (argc > 2) return (usage());
  47.       if ( ((i = argv[1][0]) != '-') && (i != '/') )
  48.          return(usage());
  49.       if (strnicmp(argv[1] + 1, "nocheck", strlen(argv[1]) - 1) != 0)
  50.          return(usage());
  51.       flag = 1;
  52.       buffer[0] = '\0';
  53.    }
  54.  
  55.    if (flag == 0) {
  56.       printf("\x16\x11\x11");   /* ^V^Q^Q = query the driver */
  57.  
  58.       for (i=0; i < 80, kbhit(); i++)
  59.          if ((ch = getch()) == (int)'\r') {
  60.             buffer[i] = '\0';
  61.             break;
  62.          }
  63.          else
  64.             buffer[i] = (char)ch;
  65.  
  66.       if (strncmp(buffer, "AVT", 3)) {
  67.          printf(two_strings,
  68.                 hello+3,
  69.                 "AVATAR console not detected. Program aborting.");
  70.          return 2;
  71.       }
  72.    }
  73.  
  74.    printf(two_strings, hello, buffer);
  75.    locate(21, 1);
  76.    printf("Controls: PgUp and PgDn offset +/- 100. ^PgUp and ^PgDn segment"
  77.            " +/- 1000.\n"
  78.           "Alt-PgUp and Alt-PgDn offset +/- 1000 (enhanced keyboard only).\n"
  79.           "\x16\x01oPress <ESC> to quit.");
  80.  
  81.    memdisp();
  82.    printf("\x16\x12");       /* reset the driver */
  83.    locate(24, 1);
  84.  
  85.    return 0;
  86. }
  87.  
  88. void memdisp(void) {
  89.  
  90.    unsigned int    register  i;  
  91.    unsigned char   register *ptr;
  92.    char     far   *address;
  93.    unsigned        segment, offset;
  94.    unsigned        bsegment, boffset;
  95.    unsigned char   buffer[256];
  96.    char            userhit;
  97.  
  98.    printf("\x16\x16G"      /* define window 'G' */
  99.           "\x03\x03\x01\x14\x50"  /* attrib: 3, corners: 3, 1, 20, 80 */
  100.           "\x16\x17G"      /* switch to window 'G' */
  101.           "\x16\x0F"       /* turn clockwise mode on */
  102.           "\xC9\x19\xCD\x10\x89\xD1\x19\xCD\x44\xBB\x19\xBA\x10\x90\xBC"
  103.           "\x19\xCD\x44\xCF\x19\xCD\x10\x89\xC8\x19\xBA\x10\x90"/* frame */
  104.           "\x16\x1E"       /* turn vertical mode on */
  105.           "\x16\x08\x02\x0B"  /* locate start of thin line */
  106.           "\x19\xB3\x10\x90"  /* draw the thin line */
  107.           "\x16\x16G"      /* redefine window 'G' */
  108.           "\x03\04\x02\x13\x10\x9A" /* attr: 3, corners: 4, 2, 19, 10 */
  109.           "\x16\x08\x01\x01"  /* locate 1, 1 */
  110.           "\x19\x30\x40"      /* print 0's */
  111.           "\x19\:\x10\x90"      /* print 16 colons vertically */
  112.           "\x19\x30\x20"      /* print 0's */
  113.           "0123456789ABCDEF"
  114.           "\x16\x22"          /* turn wrap off */
  115.           "\x19\x30\x10\x90"      /* print 0's */
  116.           "\x16\x16\x01"      /* define window 1 */
  117.           "\x07\x04\x0C\x13\x4F" /* attr: 7, corners: 4, 12, 19, 79 */
  118.           "\x16\x17\x01"      /* switch to window 1 */
  119.           );
  120.  
  121.    segment = offset = 0;
  122.  
  123.    address = (void far *)buffer;
  124.    bsegment = FP_SEG(address);
  125.    boffset  = FP_OFF(address);
  126.  
  127.    for (;;) {
  128.       do {
  129.          locate(1, 1);
  130.          movedata(segment, offset, bsegment, boffset, 256);
  131.  
  132.          for (i = 0; i < 256; i += 16) {
  133.             ptr = buffer + i+15;
  134.             printf(" %.2X %.2X %.2X %.2X %.2X %.2X %.2X %.2X"
  135.                    "-%.2X %.2X %.2X %.2X %.2X %.2X %.2X %.2X",
  136.                    *ptr--, *ptr--, *ptr--, *ptr--,
  137.                    *ptr--, *ptr--, *ptr--, *ptr--,
  138.                    *ptr--, *ptr--, *ptr--, *ptr--,
  139.                    *ptr--, *ptr--, *ptr--, *ptr--);
  140.             ptr = buffer + i+15;
  141.             printf("  %c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c\r\x16\x04",
  142.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  143.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  144.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  145.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  146.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  147.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  148.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  149.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  150.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  151.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  152.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  153.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  154.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  155.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  156.                    (*ptr-- >= ' ') ? ptr[1] : '.',
  157.                    (*ptr-- >= ' ') ? ptr[1] : '.');
  158.  
  159.          }
  160.       } while (!kbhit());
  161.  
  162.       if ((userhit = getch()) == '\x1b')
  163.          return;
  164.  
  165.       if (userhit == '\0')
  166.          switch (getch()) {
  167.  
  168.             case 0x49:        /* Page Up */
  169.                newoffset(offset -= 0x100);
  170.                break;
  171.             case 0x51:        /* Page Down */
  172.                newoffset(offset += 0x100);
  173.                break;
  174.             case 0x84:        /* ^Page Up */
  175.                newsegment(segment -= 0x1000);
  176.                break;
  177.             case 0x76:        /* ^Page Down */
  178.                newsegment(segment += 0x1000);
  179.                break;
  180.             case 0x99:        /* Alt-Page Up - enhanced kbd only */
  181.                newoffset(offset -=0x1000);
  182.                break;
  183.             case 0xA1:           /* Alt-Page Down - same restrcition */
  184.                newoffset(offset +=0x1000);
  185.                break;
  186.             default:
  187.                printf(beep);
  188.          }
  189.       else printf(beep);
  190.    }
  191. }
  192.  
  193. void newoffset(unsigned offset) {
  194.  
  195.    printf("\x16\x17G"   /* switch to window 'G' */
  196.           "\x16\x08\x01\x06" /* locate 1,6 */
  197.           "\x19%X\x10\x90\n" /* print the high byte 16 times */
  198.           "\x19%X\x10\x90"   /* print the low byte 16 times */
  199.           "\x16\x17\x01",    /* return to window 1 */
  200.           offset >> 12,      /* the new offset */
  201.           ((offset >> 8) & 0x0f));
  202.  
  203. }
  204.  
  205. void newsegment(unsigned segment) {
  206.  
  207.    printf("\x16\x17G"   /* switch to window 'G' */
  208.           "\x16\x08\x01\x01" /* locate 1,1 */
  209.           "\x19%X\x10\x90"   /* print the new segment 16 times */
  210.           "\x16\x17\x01",    /* return to window 1 */
  211.           segment >> 12);    /* the new segment */
  212.  
  213. }
  214.  
  215. int usage(void) {
  216.  
  217.    printf("\nUsage:\n\n\tmemdisp [-nocheck]\n\n");
  218.    return 2;
  219. }
  220.  
  221.