Small patch.
[wine/multimedia.git] / console / generic.c
blob8502b272c472d9bbd61f79c6c3115ba231fa5dbb
1 /* generic.c */
3 /* This is a driver to implement, when possible, "high-level"
4 routines using only low level calls. This is to make it possible
5 to have accelerated functions for the individual drivers...
6 or to simply not bother with them. */
8 /* When creating new drivers, you need to assign all the functions that
9 that driver supports into the driver struct. If it is a supplementary
10 driver, it should make sure to perserve the old values. */
12 #include <stdio.h>
14 #include "console.h"
15 #include "config.h"
16 #include "debug.h"
18 static void GENERIC_MoveLine(char row1, char row2, char col1, char col2);
19 static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
20 int attribute);
21 void GENERIC_Start()
23 /* Here, we only want to add a driver if there is not one already
24 defined. */
26 TRACE(console, "GENERIC_Start\n");
28 if (!driver.clearWindow)
29 driver.clearWindow = GENERIC_ClearWindow;
31 if (!driver.scrollUpWindow)
32 driver.scrollUpWindow = GENERIC_ScrollUpWindow;
34 if (!driver.scrollDownWindow)
35 driver.scrollDownWindow = GENERIC_ScrollDownWindow;
37 if (!driver.getCharacter)
38 driver.getCharacter = GENERIC_GetCharacter;
41 void GENERIC_ClearWindow(char row1, char col1, char row2, char col2,
42 int bg_color, int attribute)
44 char trow, tcol, x;
45 int old_refresh;
47 /* Abort if we have only partial functionality */
48 if (!(driver.getCursorPosition && driver.moveCursor && driver.write))
49 return;
51 old_refresh = CONSOLE_GetRefresh();
52 CONSOLE_SetRefresh(FALSE);
54 CONSOLE_GetCursorPosition(&trow, &tcol);
56 for (x = row1; x <= row2; x++)
57 GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
59 CONSOLE_MoveCursor(trow, tcol);
61 CONSOLE_SetRefresh(old_refresh);
64 void GENERIC_ScrollUpWindow(char row1, char col1, char row2, char col2,
65 char lines, int bg_color, int attribute)
67 /* Scroll Up Window: Characters go down */
69 char trow, tcol;
70 int old_refresh, x;
72 TRACE(console, "Scroll Up %d lines from %d to %d.\n", lines, row1,
73 row2);
75 /* Abort if we have only partial functionality */
76 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
77 && driver.getCharacterAtCursor && driver.clearWindow))
78 return;
80 /* Save initial state... */
81 old_refresh = CONSOLE_GetRefresh();
82 CONSOLE_SetRefresh(FALSE);
83 CONSOLE_GetCursorPosition(&trow, &tcol);
85 for (x = row1 + lines; x <= row2; x++)
87 GENERIC_MoveLine(x, x - lines, col1, col2);
88 GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
91 /* Restore State */
92 CONSOLE_MoveCursor(trow, tcol);
93 CONSOLE_SetRefresh(old_refresh);
96 void GENERIC_ScrollDownWindow(char row1, char col1, char row2, char col2,
97 char lines, int bg_color, int attribute)
99 /* Scroll Down Window: Characters go up */
101 char trow, tcol;
102 int old_refresh, x;
104 /* Abort if we have only partial functionality */
105 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
106 && driver.getCharacterAtCursor && driver.clearWindow))
107 return;
109 /* Save initial state... */
110 old_refresh = CONSOLE_GetRefresh();
111 CONSOLE_SetRefresh(FALSE);
112 CONSOLE_GetCursorPosition(&trow, &tcol);
114 for (x = row2; x >= row1 + lines; x--)
116 GENERIC_MoveLine(x, x + lines, col1, col2);
117 GENERIC_ClearLine(x, col1, col1, bg_color, attribute);
120 /* Restore State */
121 CONSOLE_MoveCursor(trow, tcol);
122 CONSOLE_SetRefresh(old_refresh);
125 char GENERIC_GetCharacter()
127 /* Keep getting keys until we get one with a char value */
128 char ch = (char) 0, scan;
130 while (!ch)
132 CONSOLE_GetKeystroke(&scan, &ch);
134 return ch;
137 static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
138 int attribute)
140 /* This function is here to simplify the logic of the scroll and clear
141 functions but may be useful elsewhere. If it can be used from
142 outside here, it should be made non-static */
144 int x;
146 TRACE(console, "Clear Line: %d from %d to %d.\n", row, col1, col2);
148 for (x = col1; x <= col2; x++)
150 CONSOLE_MoveCursor(row, x);
151 CONSOLE_Write(' ', 0, 0, 0);
154 /* Assume that the calling function will make sure that the cursor is
155 repositioned properly. If this becomes non-static, that will need to be
156 changed. */
159 static void GENERIC_MoveLine(char row1, char row2, char col1, char col2)
161 /* This function is here to simplify the logic of the scroll and clear
162 functions but may be useful elsewhere. If it can be used from
163 outside here, it should be made non-static */
165 int x;
166 int bg_color, fg_color, attribute;
167 char ch;
169 TRACE(console, "Move Line: Move %d to %d.\n", row1, row2);
171 for (x = col1; x <= col2; x++)
173 CONSOLE_MoveCursor(row1, x);
174 CONSOLE_GetCharacterAtCursor(&ch, &fg_color, &bg_color, &attribute);
175 CONSOLE_MoveCursor(row2, x);
176 CONSOLE_Write(ch, fg_color, bg_color, attribute);
179 /* Assume that the calling function will make sure that the cursor is
180 repositioned properly. If this becomes non-static, that will need to be
181 changed. */