2 * Copyright 1999 - Joseph Pranevich
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.
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.
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.
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
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
26 driver, it should make sure to preserve the old values. */
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(console
);
37 static void GENERIC_MoveLine(char row1
, char row2
, char col1
, char col2
);
38 static void GENERIC_ClearLine(char row
, char col1
, char col2
, int bgcolor
,
40 void GENERIC_Start(void)
42 /* Here, we only want to add a driver if there is not one already
45 TRACE("GENERIC_Start\n");
47 if (!driver
.clearWindow
)
48 driver
.clearWindow
= GENERIC_ClearWindow
;
50 if (!driver
.scrollUpWindow
)
51 driver
.scrollUpWindow
= GENERIC_ScrollUpWindow
;
53 if (!driver
.scrollDownWindow
)
54 driver
.scrollDownWindow
= GENERIC_ScrollDownWindow
;
56 if (!driver
.getCharacter
)
57 driver
.getCharacter
= GENERIC_GetCharacter
;
60 void GENERIC_ClearWindow(char row1
, char col1
, char row2
, char col2
,
61 int bg_color
, int attribute
)
66 /* Abort if we have only partial functionality */
67 if (!(driver
.getCursorPosition
&& driver
.moveCursor
&& driver
.write
))
70 old_refresh
= CONSOLE_GetRefresh();
71 CONSOLE_SetRefresh(FALSE
);
73 CONSOLE_GetCursorPosition(&trow
, &tcol
);
75 for (x
= row1
; x
<= row2
; x
++)
76 GENERIC_ClearLine(x
, col1
, col2
, bg_color
, attribute
);
78 CONSOLE_MoveCursor(trow
, tcol
);
80 CONSOLE_SetRefresh(old_refresh
);
83 void GENERIC_ScrollUpWindow(char row1
, char col1
, char row2
, char col2
,
84 char lines
, int bg_color
, int attribute
)
86 /* Scroll Up Window: Characters go down */
91 TRACE("Scroll Up %d lines from %d to %d.\n", lines
, row1
,
94 /* Abort if we have only partial functionality */
95 if (!(driver
.getCursorPosition
&& driver
.moveCursor
&& driver
.write
96 && driver
.getCharacterAtCursor
&& driver
.clearWindow
))
99 /* Save initial state... */
100 old_refresh
= CONSOLE_GetRefresh();
101 CONSOLE_SetRefresh(FALSE
);
102 CONSOLE_GetCursorPosition(&trow
, &tcol
);
104 for (x
= row1
+ lines
; x
<= row2
; x
++)
106 GENERIC_MoveLine(x
, x
- lines
, col1
, col2
);
107 GENERIC_ClearLine(x
, col1
, col2
, bg_color
, attribute
);
111 CONSOLE_MoveCursor(trow
, tcol
);
112 CONSOLE_SetRefresh(old_refresh
);
115 void GENERIC_ScrollDownWindow(char row1
, char col1
, char row2
, char col2
,
116 char lines
, int bg_color
, int attribute
)
118 /* Scroll Down Window: Characters go up */
123 /* Abort if we have only partial functionality */
124 if (!(driver
.getCursorPosition
&& driver
.moveCursor
&& driver
.write
125 && driver
.getCharacterAtCursor
&& driver
.clearWindow
))
128 /* Save initial state... */
129 old_refresh
= CONSOLE_GetRefresh();
130 CONSOLE_SetRefresh(FALSE
);
131 CONSOLE_GetCursorPosition(&trow
, &tcol
);
133 for (x
= row2
; x
>= row1
+ lines
; x
--)
135 GENERIC_MoveLine(x
, x
+ lines
, col1
, col2
);
136 GENERIC_ClearLine(x
, col1
, col1
, bg_color
, attribute
);
140 CONSOLE_MoveCursor(trow
, tcol
);
141 CONSOLE_SetRefresh(old_refresh
);
144 char GENERIC_GetCharacter()
146 /* Keep getting keys until we get one with a char value */
147 char ch
= (char) 0, scan
;
151 CONSOLE_GetKeystroke(&scan
, &ch
);
156 static void GENERIC_ClearLine(char row
, char col1
, char col2
, int bgcolor
,
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 */
165 TRACE("Clear Line: %d from %d to %d (unused: bgcolor %d, attrib %d).\n", row
, col1
, col2
, bgcolor
, attribute
);
167 for (x
= col1
; x
<= col2
; x
++)
169 CONSOLE_MoveCursor(row
, x
);
170 CONSOLE_Write(' ', 0, 0, 0);
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
178 static void GENERIC_MoveLine(char row1
, char row2
, char col1
, char col2
)
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 */
185 int bg_color
, fg_color
, attribute
;
188 TRACE("Move Line: Move %d to %d.\n", row1
, row2
);
190 for (x
= col1
; x
<= col2
; x
++)
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
);
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