home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / calculat / rpn30src.zip / RPNSCRNS.C < prev   
C/C++ Source or Header  |  1990-05-30  |  4KB  |  155 lines

  1. /*
  2.  * RPNSCRNS
  3.  *
  4.  * Get input characters.
  5.  * Maintain the Help windows.
  6.  *
  7.  * 90.05.23 v3.0
  8.  *    A new startup() routine can change the colors of the screens.
  9.  *    Special-key tag changed from 0x7f00 to 0x1b00 --- this is consistent
  10.  *    with the actual first byte of the extended scan code (no big deal).
  11.  *    Optional savefile-output added.
  12.  *    Help screens toggle from one to another.
  13.  *    display() and related functions split out to display.c
  14.  * 89.12.23
  15.  */
  16.  
  17. #include <conio.h>
  18. #include "rpn.h"
  19. #include "rpnio.h"
  20. #include "helpscrn.h"
  21. #define FRAME_ALLOC
  22. #include "display.h"
  23. #include "debug.h"
  24.  
  25.  
  26. static int orig_x, orig_y;
  27.  
  28. /*
  29.  * h1_buffer saves the original screen under the Help windows.
  30.  */
  31. static char h1_buffer[ 2 * H_WIDTH * H_DEPTH ];
  32.  
  33.  
  34. /* /////////////////////////////////////////////////////////////////////// */
  35.  
  36. #define NPOS (D_WIDTH+D_WIDTH+3)
  37. #define FPOS (D_WIDTH+D_WIDTH+D_WIDTH+D_WIDTH+3)
  38. #define OPOS (D_WIDTH+D_WIDTH+D_WIDTH+D_WIDTH+D_WIDTH+D_WIDTH+3)
  39.  
  40. void startup(void)
  41. {
  42.     unsigned color;
  43.  
  44.     /*
  45.     | Save the original screen under the Help screens, just in case.
  46.     */
  47.     gettext(H_LEFT, H_TOP, H_RIGHT, H_BOTTOM, h1_buffer);
  48.  
  49.     /*
  50.     | Discover the display window's colors, and use them.
  51.     */
  52.     D_NUM = (int)((char)0x8f & (frame[NPOS]));
  53.     D_FTN = (int)((char)0x8f & (frame[FPOS]));
  54.     D_OOPS = (int)((char)0x8f & (frame[OPOS]));
  55.     color = frame[1];
  56.     D_BKGND = (0x0070 & color);
  57.     D_BORDER = (0x008f & color);
  58.     textattr(color);
  59.  
  60.     if (0 >= TOP)    TOP = 6;    /** Ensure a legal    **/
  61.     if (0 >= LEFT)    LEFT = 39;    /**  starting position.    **/
  62.  
  63.     orig_sl = scrolllock = *(char far *)ksp & SCROLL_LOCK;
  64.     orig_x = wherex();
  65.     orig_y = wherey();
  66. }
  67.  
  68. /* /////////////////////////////////////////////////////////////////////// */
  69.  
  70. void shutdown(void) {
  71.     window(1,1, 80,25);
  72.     if (help_flag > 0)
  73.         gotoxy(1, 24);          /* Put cursor at "almost" lower left. */
  74.     else
  75.         gotoxy(orig_x, orig_y); /* Reestablish original cursor position. */
  76. }
  77.  
  78. /* /////////////////////////////////////////////////////////////////////// */
  79.  
  80. /*-------------------------------------------------------------------------*
  81. | Cycle through the help screens.
  82. */
  83.  
  84. static char *scrntbl[3] = { h1_buffer, help1, help2 };
  85.  
  86. void toggle_help(void)
  87. {
  88.     if (++help_flag >= 3)    /** Cycle to next screen. **/
  89.     help_flag = 0;
  90.  
  91.     puttext(H_LEFT, H_TOP, H_RIGHT, H_BOTTOM, (void *)scrntbl[ help_flag ]);
  92. }
  93.  
  94. /* /////////////////////////////////////////////////////////////////////// */
  95.  
  96. /*---------------------------------------------------------------------*\
  97. | Get keyboard input.                            |
  98. | Getch() returns one or two bytes from a PC keyboard (depending on    |
  99. | the key, naturally).  If the first byte is 0, meaning that there    |
  100. | IS a second byte, a value outside the normal character range is    |
  101. | created by OR'ing the the second byte with 0x1b00.            |
  102. |                                    |
  103. | getkey() also cleans up the error-message line, because this is    |
  104. | a convenient place to do it.                        |
  105. \* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  106. int getkey(void)
  107. {
  108.     int c, k;
  109.  
  110.     DBG_FPRINTF((errfile,"\ngetkey:  scrolllock: %#x, *ksp: %#x, ",
  111.     scrolllock, *(char far *)ksp));
  112.  
  113.     while (!kbhit() && (scrolllock == (*(char far *)ksp & SCROLL_LOCK)))
  114.     ;
  115.     if (scrolllock != (k = *(char far *)ksp & SCROLL_LOCK)) {
  116.     scrolllock = k;
  117.     c = -1;
  118.     } else
  119.     if ( 0 == (c = getch()) ) {
  120.             c = 0x1b00 | getch();
  121.     }
  122.  
  123.     DBG_FPRINTF((errfile,"getkey: %#x, scroll %x\n", c, k));
  124.  
  125.     /* Put the original display border back, in case of error messages */
  126.     puttext( LEFT, MSG_LINE, RIGHT, MSG_LINE,
  127.         (void *)( frame + (6 * 2 * D_WIDTH) ) );
  128.     window(S_LEFT, MSG_LINE, RIGHT, MSG_LINE);
  129.     return c;
  130. }
  131.  
  132. /* /////////////////////////////////////////////////////////////////////// */
  133.  
  134. void open_savefile(const char *fn)
  135. {
  136.     if ( 0 != (savefile = fopen(fn, "ab")) ) {
  137.     setvbuf(savefile, NULL, _IOLBF, 161);
  138.     fprintf(savefile,
  139.         "%s\r\nFunction      Y-, X-;   LastX registers\r\n",
  140.         version);
  141.     } else
  142.     prterr(fn, "can't open file.\n");
  143. }
  144.  
  145. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  146.  
  147. void close_savefile(void)
  148. {
  149.     fputs("\r\n", savefile);
  150.     fclose(savefile);
  151.     savefile = NULL;
  152. }
  153.  
  154. /*\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\*/
  155.