home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / mc454src.zip / mc-4.5.4.src / os2emx / src / cons_os2.c < prev    next >
C/C++ Source or Header  |  1999-01-04  |  3KB  |  112 lines

  1. /* Client interface for General purpose OS/2 console save/restore server.
  2.         1997 Alexander Dong <ado@software-ag.de>
  3.    Having the same interface as its Linux counterpart:
  4.        Copyright (C) 1994 Janne Kukonlehto <jtklehto@stekt.oulu.fi> 
  5.    
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.    
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
  19.    
  20. */
  21.  
  22. #include <config.h>
  23.  
  24. #define INCL_BASE
  25. #define INCL_NOPM
  26. #define INCL_VIO
  27. #define INCL_KBD
  28. #define INCL_DOS
  29. #define INCL_SUB
  30. #define INCL_DOSERRORS
  31. #include <os2.h>
  32.  
  33.  
  34. #include "src/tty.h"
  35. #include "src/util.h"
  36. #include "src/win.h"
  37. #include "src/cons.saver.h"
  38.  
  39. int    cons_saver_pid = 1;
  40.  
  41. signed char console_flag = 1;
  42. static unsigned char *scr_buffer;
  43. static unsigned char *pointer;
  44.  
  45. int GetScrRows();
  46. int GetScrCols();
  47.  
  48. int GetScrRows()
  49. {
  50.    VIOMODEINFO pvMode = {80};
  51.    unsigned int hVio = 0;
  52.    VioGetMode(&pvMode, hVio);
  53.    return (pvMode.row ? pvMode.row: 25);
  54. }
  55.  
  56. int GetScrCols()
  57. {
  58.    VIOMODEINFO pvMode = {80};
  59.    unsigned int hVio = 0;
  60.    VioGetMode(&pvMode, hVio);
  61.    return (pvMode.col>80 ? pvMode.col: 80);
  62. }
  63.  
  64. void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line)
  65. {
  66.    int col = GetScrCols();
  67.    int row = GetScrRows();
  68.    int n;
  69.    register int z;
  70.  
  71.    pointer = scr_buffer;
  72.    for (z=0; z<(begin_line * col); z++) {
  73.       pointer++; pointer++;
  74.    }
  75.    n = (end_line - begin_line + 1) * col;
  76.    VioWrtCellStr((PCH) pointer, (USHORT) n, begin_line, 0, 0);
  77.    return;
  78. }
  79.  
  80. void handle_console (unsigned char action)
  81. {
  82.    static int col;
  83.    static int row;
  84.    int        n;
  85.  
  86.    switch (action) {
  87.    case CONSOLE_INIT:           /* Initialize */
  88.       col = GetScrCols();
  89.       row = GetScrRows();
  90.       scr_buffer = (unsigned char *) malloc(col * row * 2);  /* short values */
  91.       n = col * row * 2;
  92.       VioReadCellStr((PCH) scr_buffer,(USHORT *)&n, 0, 0, 0); /* Just save it */
  93.       break;
  94.    case CONSOLE_DONE:
  95.       free(scr_buffer);
  96.       break;
  97.    case CONSOLE_SAVE:           /* Save the screen */
  98.       n = col * row * 2;
  99.       VioReadCellStr((PCH) scr_buffer, (USHORT *) &n, 0, 0, 0);
  100.       break;
  101.    case CONSOLE_RESTORE:
  102.       n = col * row * 2;
  103.       VioWrtCellStr ((PCH) scr_buffer, (USHORT) n, 0, 0, 0); /* Write it back */
  104.       break;
  105.    default: 
  106.       /* This is not possible, but if we are here, just save the screen */
  107.       handle_console(CONSOLE_SAVE);
  108.      break;
  109.    }
  110.    return;
  111. }
  112.