cons_os2.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  16. */
  17. #include <config.h>
  18. #ifdef __os2__
  19. #define INCL_BASE
  20. #define INCL_NOPM
  21. #define INCL_VIO
  22. #define INCL_KBD
  23. #define INCL_DOS
  24. #define INCL_SUB
  25. #define INCL_DOSERRORS
  26. #include <os2.h>
  27. #endif
  28. #include "../src/tty.h"
  29. #include "../src/util.h"
  30. #include "../src/win.h"
  31. #include "../src/cons.saver.h"
  32. signed char console_flag = 1;
  33. static unsigned char *scr_buffer;
  34. static unsigned char *pointer;
  35. static int GetScrRows();
  36. static int GetScrCols();
  37. static int GetScrRows()
  38. {
  39. VIOMODEINFO pvMode = {80};
  40. unsigned int hVio = 0;
  41. VioGetMode(&pvMode, hVio);
  42. return (pvMode.row ? pvMode.row: 25);
  43. }
  44. static int GetScrCols()
  45. {
  46. VIOMODEINFO pvMode = {80};
  47. unsigned int hVio = 0;
  48. VioGetMode(&pvMode, hVio);
  49. return (pvMode.col ? pvMode.col: 80);
  50. }
  51. void show_console_contents (int starty, unsigned char begin_line, unsigned char end_line)
  52. {
  53. int col = GetScrCols();
  54. int row = GetScrRows();
  55. int n;
  56. register int z;
  57. pointer = scr_buffer;
  58. for (z=0; z<(begin_line * col); z++) {
  59. pointer++; pointer++;
  60. }
  61. n = (end_line - begin_line + 1) * col;
  62. VioWrtCellStr((PCH) pointer, (USHORT) n, begin_line, 0, 0);
  63. return;
  64. }
  65. void handle_console (unsigned char action)
  66. {
  67. static int col;
  68. static int row;
  69. int n;
  70. switch (action) {
  71. case CONSOLE_INIT: /* Initialize */
  72. col = GetScrCols();
  73. row = GetScrRows();
  74. scr_buffer = (unsigned char *) malloc(col * row * 2); /* short values */
  75. n = col * row * 2;
  76. VioReadCellStr((PCH) scr_buffer, (USHORT *) &n, 0, 0, 0); /* Just save it */
  77. break;
  78. case CONSOLE_DONE:
  79. free(scr_buffer);
  80. break;
  81. case CONSOLE_SAVE: /* Save the screen */
  82. n = col * row * 2;
  83. VioReadCellStr((PCH) scr_buffer, (USHORT *) &n, 0, 0, 0);
  84. break;
  85. case CONSOLE_RESTORE:
  86. n = col * row * 2;
  87. VioWrtCellStr ((PCH) scr_buffer, (USHORT) n, 0, 0, 0); /* Write it back */
  88. break;
  89. default:
  90. /* This is not possible, but if we are here, just save the screen */
  91. handle_console(CONSOLE_SAVE);
  92. break;
  93. }
  94. return;
  95. }