home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / ONE_ON_9.ZIP / ONE_ON_9.C next >
Encoding:
C/C++ Source or Header  |  1988-03-07  |  3.4 KB  |  136 lines

  1. /* ONE_ON_NINE.C - From page 75 of Volume 4, Number 2, the February    */
  2. /* 1987 issue of Computer Language. The article is by Jean-Pierre      */
  3. /* Schachter and is entitled DATA STRUCTURES AND SCROLLING.            */
  4. /*                                                                     */
  5. /* Usage:   A>one_on_9 <RET>                                           */
  6. /***********************************************************************/
  7.  
  8. #define REQUEST (request = get_scan())
  9. #define FINISHED 1
  10. #define MOVE_LEFT case 75
  11. #define MOVE_RIGHT case 77
  12. #define MOVE_UP case 72
  13. #define MOVE_DOWN case 80
  14. #define RIGHT --pb
  15. #define LEFT ++pb
  16. #define DOWN pb -= 240
  17. #define UP pb += 240
  18. #define TO_CENTER pb += 6080
  19. #define IS ==
  20. #define IS_NOT !=
  21. #define SHOULD switch
  22. #define BE
  23. #define BEEP 7
  24. #define CLRSCR puts(clrscr)
  25.  
  26. #include <stdio.h>
  27. #include <malloc.h>
  28. #include <memory.h>
  29. #include <conio.h>
  30. #include <dos.h>
  31.  
  32. char *pb, *line[25];
  33.  
  34. main()
  35. {
  36. static char clrscr[] = { 27, "[2J\0" };
  37.  
  38.    pb = memset(malloc (18000), ' ', 18000);
  39.    CLRSCR;
  40.    move_it(TO_CENTER);        /* CENTERS DISPLAY ON V. SCR.     */
  41.    mess_it();                 /* WRITES JUNK TO V. SCR.         */
  42.    show_it();                 /* DISPLAYS THE V. SCREEN         */
  43.    scrl_it();                 /* SCROLLS THE DISPLAY            */
  44.    CLRSCR;
  45.    exit(0);
  46. }
  47.  
  48. /* ================== Function scrl_it() =======================*/
  49.  
  50. scrl_it()      /* THE READ AND INTERRUPT LOOP */
  51. {
  52. char request = 0, income();
  53.  
  54.    while (REQUEST IS_NOT FINISHED) {
  55.       SHOULD (request) BE {
  56.          MOVE_RIGHT:
  57.             move_it(RIGHT);
  58.             show_it();
  59.             break;
  60.          MOVE_LEFT:
  61.             move_it(LEFT);
  62.             show_it();
  63.             break;
  64.          MOVE_UP:
  65.             move_it(UP);
  66.             show_it();
  67.             break;
  68.          MOVE_DOWN:
  69.             move_it(DOWN);
  70.             show_it();
  71.             break;
  72.          default:
  73.             putchar(7);
  74.             break;
  75.       }
  76.    }
  77. }
  78.  
  79. /* ====================== Function move_it() ========================= */
  80.  
  81. move_it(start)             /* SHIFTS THE VIRTUAL SCREEN */
  82. struct gapl {
  83.    char space[240];
  84. } *start;
  85. {
  86. register int i = -1;
  87.  
  88.    while (i++ < 24)
  89.       line[i] = (char *)start++;
  90. }
  91.  
  92. /* ====================== Function mess_it() ==========================*/
  93.  
  94. mess_it()                  /* INITIALIZES THE VIRTUAL SCREEN */
  95. {
  96. register int k = -1, l;
  97. char *v;
  98.  
  99.    while (k++ < 24) {
  100.       v = line[k];
  101.       for (l = 0; l < 80; l++)
  102.          *v++ = 65 + k + l;
  103.    }
  104. }
  105.  
  106. /* ====================== Function show_it() ========================= */
  107.  
  108. show_it()                  /* THE SWAP TO SCREEN MEMORY */
  109. {
  110. register int d, e = -1;
  111. struct TWO_STEP {
  112.    char letter[2];
  113. } far *next;
  114. struct NEXTLIN {
  115.    struct TWO_STEP ligne[80];
  116. } far *lin_head = (struct NEXTLIN far *)(0xB000L << 16);
  117.  
  118.    while (e++ < 24) {
  119.       next = (struct TWO_STEP far *) lin_head++;
  120.       for (d = 0; d < 80; d++)
  121.          next++->letter[0] = *(line[e] + d);
  122.    }
  123. }
  124.  
  125. /* ====================== Function get_scan() ======================== */
  126.  
  127. get_scan()      /* NON-ECHO NON-CR INPUT RETURNS SCAN CODE, = */
  128. {                    /* NOT ASCII = USE utreg.h.al FOR ASCII ===== */
  129. union REGS inreg, utreg;
  130.  
  131.    inreg.h.ah = 0;
  132.    int86 (0x16, &inreg, &utreg);    /* KEYBOARD INT 0x16 */
  133.    return (utreg.h.ah);
  134. }
  135.  
  136.