blob: effa6eaae335a830b75ebbc702f88cd758748823 [file] [log] [blame]
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00001/*
2 * Copyright 1999 - Joseph Pranevich
3 *
4 * This is a driver to implement, when possible, "high-level"
5 * routines using only low level calls. This is to make it possible
6 * to have accelerated functions for the individual drivers...
7 * or to simply not bother with them.
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000023
24/* When creating new drivers, you need to assign all the functions that
25 that driver supports into the driver struct. If it is a supplementary
Andreas Mohra6d83eb2000-12-27 04:02:46 +000026 driver, it should make sure to preserve the old values. */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000027
Francois Gougete5ddd262001-10-14 16:18:52 +000028#include "config.h"
29
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000030#include <stdio.h>
Joseph Pranevich55768381998-12-09 15:43:03 +000031
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000032#include "console.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000033#include "wine/debug.h"
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000034
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000035WINE_DEFAULT_DEBUG_CHANNEL(console);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000036
Joseph Pranevichd87fa941999-01-03 16:15:12 +000037static void GENERIC_MoveLine(char row1, char row2, char col1, char col2);
38static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
39 int attribute);
Eric Pouechd57f7d12000-04-09 18:40:32 +000040void GENERIC_Start(void)
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000041{
42 /* Here, we only want to add a driver if there is not one already
43 defined. */
44
Alexandre Julliard9fe7a251999-05-14 08:17:14 +000045 TRACE("GENERIC_Start\n");
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000046
47 if (!driver.clearWindow)
48 driver.clearWindow = GENERIC_ClearWindow;
49
50 if (!driver.scrollUpWindow)
51 driver.scrollUpWindow = GENERIC_ScrollUpWindow;
52
53 if (!driver.scrollDownWindow)
54 driver.scrollDownWindow = GENERIC_ScrollDownWindow;
55
56 if (!driver.getCharacter)
57 driver.getCharacter = GENERIC_GetCharacter;
58}
59
60void GENERIC_ClearWindow(char row1, char col1, char row2, char col2,
61 int bg_color, int attribute)
62{
Joseph Pranevichd87fa941999-01-03 16:15:12 +000063 char trow, tcol, x;
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000064 int old_refresh;
65
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000066 /* Abort if we have only partial functionality */
67 if (!(driver.getCursorPosition && driver.moveCursor && driver.write))
68 return;
69
70 old_refresh = CONSOLE_GetRefresh();
71 CONSOLE_SetRefresh(FALSE);
72
73 CONSOLE_GetCursorPosition(&trow, &tcol);
74
Joseph Pranevichd87fa941999-01-03 16:15:12 +000075 for (x = row1; x <= row2; x++)
76 GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000077
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000078 CONSOLE_MoveCursor(trow, tcol);
79
80 CONSOLE_SetRefresh(old_refresh);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000081}
82
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000083void GENERIC_ScrollUpWindow(char row1, char col1, char row2, char col2,
84 char lines, int bg_color, int attribute)
85{
Joseph Pranevichd87fa941999-01-03 16:15:12 +000086 /* Scroll Up Window: Characters go down */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000087
Patrik Stridvall2c684081999-07-31 17:36:48 +000088 char trow, tcol, x;
89 int old_refresh;
Joseph Pranevichd87fa941999-01-03 16:15:12 +000090
Alexandre Julliard9fe7a251999-05-14 08:17:14 +000091 TRACE("Scroll Up %d lines from %d to %d.\n", lines, row1,
Joseph Pranevichd87fa941999-01-03 16:15:12 +000092 row2);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000093
94 /* Abort if we have only partial functionality */
95 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
96 && driver.getCharacterAtCursor && driver.clearWindow))
97 return;
Joseph Pranevichd87fa941999-01-03 16:15:12 +000098
99 /* Save initial state... */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000100 old_refresh = CONSOLE_GetRefresh();
101 CONSOLE_SetRefresh(FALSE);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000102 CONSOLE_GetCursorPosition(&trow, &tcol);
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000103
104 for (x = row1 + lines; x <= row2; x++)
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000105 {
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000106 GENERIC_MoveLine(x, x - lines, col1, col2);
107 GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
108 }
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000109
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000110 /* Restore State */
111 CONSOLE_MoveCursor(trow, tcol);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000112 CONSOLE_SetRefresh(old_refresh);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000113}
114
115void GENERIC_ScrollDownWindow(char row1, char col1, char row2, char col2,
116 char lines, int bg_color, int attribute)
117{
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000118 /* Scroll Down Window: Characters go up */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000119
Patrik Stridvall2c684081999-07-31 17:36:48 +0000120 char trow, tcol, x;
121 int old_refresh;
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000122
123 /* Abort if we have only partial functionality */
124 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
125 && driver.getCharacterAtCursor && driver.clearWindow))
126 return;
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000127
128 /* Save initial state... */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000129 old_refresh = CONSOLE_GetRefresh();
130 CONSOLE_SetRefresh(FALSE);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000131 CONSOLE_GetCursorPosition(&trow, &tcol);
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000132
133 for (x = row2; x >= row1 + lines; x--)
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000134 {
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000135 GENERIC_MoveLine(x, x + lines, col1, col2);
136 GENERIC_ClearLine(x, col1, col1, bg_color, attribute);
137 }
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000138
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000139 /* Restore State */
140 CONSOLE_MoveCursor(trow, tcol);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000141 CONSOLE_SetRefresh(old_refresh);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000142}
143
144char GENERIC_GetCharacter()
145{
146 /* Keep getting keys until we get one with a char value */
147 char ch = (char) 0, scan;
148
149 while (!ch)
150 {
Alexandre Julliard8da12c41999-01-17 16:55:11 +0000151 CONSOLE_GetKeystroke(&scan, &ch);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000152 }
153 return ch;
154}
155
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000156static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
157 int attribute)
158{
159 /* This function is here to simplify the logic of the scroll and clear
160 functions but may be useful elsewhere. If it can be used from
161 outside here, it should be made non-static */
162
Patrik Stridvall2c684081999-07-31 17:36:48 +0000163 char x;
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000164
Joerg Mayerabe635c2000-11-11 00:38:37 +0000165 TRACE("Clear Line: %d from %d to %d (unused: bgcolor %d, attrib %d).\n", row, col1, col2, bgcolor, attribute);
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000166
167 for (x = col1; x <= col2; x++)
168 {
169 CONSOLE_MoveCursor(row, x);
170 CONSOLE_Write(' ', 0, 0, 0);
171 }
172
173 /* Assume that the calling function will make sure that the cursor is
174 repositioned properly. If this becomes non-static, that will need to be
175 changed. */
176}
177
178static void GENERIC_MoveLine(char row1, char row2, char col1, char col2)
179{
180 /* This function is here to simplify the logic of the scroll and clear
181 functions but may be useful elsewhere. If it can be used from
182 outside here, it should be made non-static */
183
Patrik Stridvall2c684081999-07-31 17:36:48 +0000184 char x;
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000185 int bg_color, fg_color, attribute;
186 char ch;
187
Alexandre Julliard9fe7a251999-05-14 08:17:14 +0000188 TRACE("Move Line: Move %d to %d.\n", row1, row2);
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000189
190 for (x = col1; x <= col2; x++)
191 {
192 CONSOLE_MoveCursor(row1, x);
193 CONSOLE_GetCharacterAtCursor(&ch, &fg_color, &bg_color, &attribute);
194 CONSOLE_MoveCursor(row2, x);
195 CONSOLE_Write(ch, fg_color, bg_color, attribute);
196 }
197
198 /* Assume that the calling function will make sure that the cursor is
199 repositioned properly. If this becomes non-static, that will need to be
200 changed. */
201}