Added console support.
[wine/wine-kai.git] / console / generic.c
blobff2ea5e792700a026aa0ee9708101e134833909d
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>
13 #include "console.h"
14 #include "config.h"
15 #include "debug.h"
17 void GENERIC_Start()
19 /* Here, we only want to add a driver if there is not one already
20 defined. */
22 TRACE(console, "GENERIC_Start\n");
24 if (!driver.clearWindow)
25 driver.clearWindow = GENERIC_ClearWindow;
27 if (!driver.scrollUpWindow)
28 driver.scrollUpWindow = GENERIC_ScrollUpWindow;
30 if (!driver.scrollDownWindow)
31 driver.scrollDownWindow = GENERIC_ScrollDownWindow;
33 if (!driver.getCharacter)
34 driver.getCharacter = GENERIC_GetCharacter;
37 void GENERIC_ClearWindow(char row1, char col1, char row2, char col2,
38 int bg_color, int attribute)
40 char trow, tcol;
41 char x, y;
42 int old_refresh;
44 TRACE(console, "GENERIC_ClearWindow()\n");
45 /* Abort if we have only partial functionality */
46 if (!(driver.getCursorPosition && driver.moveCursor && driver.write))
47 return;
49 old_refresh = CONSOLE_GetRefresh();
50 CONSOLE_SetRefresh(FALSE);
52 CONSOLE_GetCursorPosition(&trow, &tcol);
54 for (x = row1; x < row2; x++)
56 CONSOLE_MoveCursor(x, col1);
58 for (y = col1; y < col2; y++)
60 CONSOLE_Write(' ', 0, bg_color, attribute);
63 CONSOLE_MoveCursor(trow, tcol);
65 CONSOLE_SetRefresh(old_refresh);
67 TRACE(console, "GENERIC_ClearWindow() completed.\n");
70 /* These are in-progress. I just haven't finished them yet... */
71 void GENERIC_ScrollUpWindow(char row1, char col1, char row2, char col2,
72 char lines, int bg_color, int attribute)
74 char trow, tcol;
75 int x, y;
76 char ch;
77 int bg, fg, attr;
78 int old_refresh;
80 TRACE(console, "GENERIC_ScrollUpWindow()\n");
82 /* Abort if we have only partial functionality */
83 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
84 && driver.getCharacterAtCursor && driver.clearWindow))
85 return;
87 old_refresh = CONSOLE_GetRefresh();
88 CONSOLE_SetRefresh(FALSE);
90 CONSOLE_GetCursorPosition(&trow, &tcol);
92 for (x = row1 + lines; x < row2; x++)
94 for (y = col1; y < col2; y++)
96 CONSOLE_MoveCursor(x, y);
97 CONSOLE_GetCharacterAtCursor(&ch, &fg, &bg, &attr);
98 CONSOLE_MoveCursor(x - lines, y);
99 CONSOLE_Write(ch, fg, bg, attr);
102 CONSOLE_ClearWindow(row2 - lines, col1, row2, col2, bg_color,
103 attribute);
104 CONSOLE_MoveCursor(trow, tcol);
106 CONSOLE_SetRefresh(old_refresh);
108 TRACE(console, "GENERIC_ScrollUpWindow() completed.\n");
111 void GENERIC_ScrollDownWindow(char row1, char col1, char row2, char col2,
112 char lines, int bg_color, int attribute)
114 char trow, tcol;
115 int x, y;
116 char ch;
117 int bg, fg, attr;
118 int old_refresh;
120 TRACE(console, "GENERIC_ScrollDownWindow()\n");
122 /* Abort if we have only partial functionality */
123 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
124 && driver.getCharacterAtCursor && driver.clearWindow))
125 return;
127 old_refresh = CONSOLE_GetRefresh();
128 CONSOLE_SetRefresh(FALSE);
130 CONSOLE_GetCursorPosition(&trow, &tcol);
132 for (x = row2 - lines; x > row1; x--)
134 for (y = col1; y < col2; y++)
136 CONSOLE_MoveCursor(x, y);
137 CONSOLE_GetCharacterAtCursor(&ch, &fg, &bg, &attr);
138 CONSOLE_MoveCursor(x + lines, y);
139 CONSOLE_Write(ch, fg, bg, attr);
142 CONSOLE_ClearWindow(row1, col1, row1 + lines, col2, bg_color,
143 attribute);
144 CONSOLE_MoveCursor(trow, tcol);
146 CONSOLE_SetRefresh(old_refresh);
148 TRACE(console, "GENERIC_ScrollDownWindow() completed.\n");
152 char GENERIC_GetCharacter()
154 /* Keep getting keys until we get one with a char value */
155 char ch = (char) 0, scan;
157 while (!ch)
159 CONSOLE_GetKeystroke(&ch, &scan);
161 return ch;