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 /* When creating new drivers, you need to assign all the functions that
10 that driver supports into the driver struct. If it is a supplementary
11 driver, it should make sure to perserve the old values. */
17 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(console)
21 static void GENERIC_MoveLine(char row1, char row2, char col1, char col2);
22 static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
24 void GENERIC_Start(void)
26 /* Here, we only want to add a driver if there is not one already
29 TRACE("GENERIC_Start\n");
31 if (!driver.clearWindow)
32 driver.clearWindow = GENERIC_ClearWindow;
34 if (!driver.scrollUpWindow)
35 driver.scrollUpWindow = GENERIC_ScrollUpWindow;
37 if (!driver.scrollDownWindow)
38 driver.scrollDownWindow = GENERIC_ScrollDownWindow;
40 if (!driver.getCharacter)
41 driver.getCharacter = GENERIC_GetCharacter;
44 void GENERIC_ClearWindow(char row1, char col1, char row2, char col2,
45 int bg_color, int attribute)
50 /* Abort if we have only partial functionality */
51 if (!(driver.getCursorPosition && driver.moveCursor && driver.write))
54 old_refresh = CONSOLE_GetRefresh();
55 CONSOLE_SetRefresh(FALSE);
57 CONSOLE_GetCursorPosition(&trow, &tcol);
59 for (x = row1; x <= row2; x++)
60 GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
62 CONSOLE_MoveCursor(trow, tcol);
64 CONSOLE_SetRefresh(old_refresh);
67 void GENERIC_ScrollUpWindow(char row1, char col1, char row2, char col2,
68 char lines, int bg_color, int attribute)
70 /* Scroll Up Window: Characters go down */
75 TRACE("Scroll Up %d lines from %d to %d.\n", lines, row1,
78 /* Abort if we have only partial functionality */
79 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
80 && driver.getCharacterAtCursor && driver.clearWindow))
83 /* Save initial state... */
84 old_refresh = CONSOLE_GetRefresh();
85 CONSOLE_SetRefresh(FALSE);
86 CONSOLE_GetCursorPosition(&trow, &tcol);
88 for (x = row1 + lines; x <= row2; x++)
90 GENERIC_MoveLine(x, x - lines, col1, col2);
91 GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
95 CONSOLE_MoveCursor(trow, tcol);
96 CONSOLE_SetRefresh(old_refresh);
99 void GENERIC_ScrollDownWindow(char row1, char col1, char row2, char col2,
100 char lines, int bg_color, int attribute)
102 /* Scroll Down Window: Characters go up */
107 /* Abort if we have only partial functionality */
108 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
109 && driver.getCharacterAtCursor && driver.clearWindow))
112 /* Save initial state... */
113 old_refresh = CONSOLE_GetRefresh();
114 CONSOLE_SetRefresh(FALSE);
115 CONSOLE_GetCursorPosition(&trow, &tcol);
117 for (x = row2; x >= row1 + lines; x--)
119 GENERIC_MoveLine(x, x + lines, col1, col2);
120 GENERIC_ClearLine(x, col1, col1, bg_color, attribute);
124 CONSOLE_MoveCursor(trow, tcol);
125 CONSOLE_SetRefresh(old_refresh);
128 char GENERIC_GetCharacter()
130 /* Keep getting keys until we get one with a char value */
131 char ch = (char) 0, scan;
135 CONSOLE_GetKeystroke(&scan, &ch);
140 static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
143 /* This function is here to simplify the logic of the scroll and clear
144 functions but may be useful elsewhere. If it can be used from
145 outside here, it should be made non-static */
149 TRACE("Clear Line: %d from %d to %d.\n", row, col1, col2);
151 for (x = col1; x <= col2; x++)
153 CONSOLE_MoveCursor(row, x);
154 CONSOLE_Write(' ', 0, 0, 0);
157 /* Assume that the calling function will make sure that the cursor is
158 repositioned properly. If this becomes non-static, that will need to be
162 static void GENERIC_MoveLine(char row1, char row2, char col1, char col2)
164 /* This function is here to simplify the logic of the scroll and clear
165 functions but may be useful elsewhere. If it can be used from
166 outside here, it should be made non-static */
169 int bg_color, fg_color, attribute;
172 TRACE("Move Line: Move %d to %d.\n", row1, row2);
174 for (x = col1; x <= col2; x++)
176 CONSOLE_MoveCursor(row1, x);
177 CONSOLE_GetCharacterAtCursor(&ch, &fg_color, &bg_color, &attribute);
178 CONSOLE_MoveCursor(row2, x);
179 CONSOLE_Write(ch, fg_color, bg_color, attribute);
182 /* Assume that the calling function will make sure that the cursor is
183 repositioned properly. If this becomes non-static, that will need to be