blob: 8502b272c472d9bbd61f79c6c3115ba231fa5dbb [file] [log] [blame]
Joseph Pranevich791cd6a1998-12-02 19:58:08 +00001/* generic.c */
2
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. */
7
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. */
11
12#include <stdio.h>
Joseph Pranevich55768381998-12-09 15:43:03 +000013
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000014#include "console.h"
15#include "config.h"
16#include "debug.h"
17
Joseph Pranevichd87fa941999-01-03 16:15:12 +000018static void GENERIC_MoveLine(char row1, char row2, char col1, char col2);
19static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
20 int attribute);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000021void GENERIC_Start()
22{
23 /* Here, we only want to add a driver if there is not one already
24 defined. */
25
26 TRACE(console, "GENERIC_Start\n");
27
28 if (!driver.clearWindow)
29 driver.clearWindow = GENERIC_ClearWindow;
30
31 if (!driver.scrollUpWindow)
32 driver.scrollUpWindow = GENERIC_ScrollUpWindow;
33
34 if (!driver.scrollDownWindow)
35 driver.scrollDownWindow = GENERIC_ScrollDownWindow;
36
37 if (!driver.getCharacter)
38 driver.getCharacter = GENERIC_GetCharacter;
39}
40
41void GENERIC_ClearWindow(char row1, char col1, char row2, char col2,
42 int bg_color, int attribute)
43{
Joseph Pranevichd87fa941999-01-03 16:15:12 +000044 char trow, tcol, x;
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000045 int old_refresh;
46
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000047 /* Abort if we have only partial functionality */
48 if (!(driver.getCursorPosition && driver.moveCursor && driver.write))
49 return;
50
51 old_refresh = CONSOLE_GetRefresh();
52 CONSOLE_SetRefresh(FALSE);
53
54 CONSOLE_GetCursorPosition(&trow, &tcol);
55
Joseph Pranevichd87fa941999-01-03 16:15:12 +000056 for (x = row1; x <= row2; x++)
57 GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000058
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000059 CONSOLE_MoveCursor(trow, tcol);
60
61 CONSOLE_SetRefresh(old_refresh);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000062}
63
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000064void GENERIC_ScrollUpWindow(char row1, char col1, char row2, char col2,
65 char lines, int bg_color, int attribute)
66{
Joseph Pranevichd87fa941999-01-03 16:15:12 +000067 /* Scroll Up Window: Characters go down */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000068
Joseph Pranevichd87fa941999-01-03 16:15:12 +000069 char trow, tcol;
70 int old_refresh, x;
71
72 TRACE(console, "Scroll Up %d lines from %d to %d.\n", lines, row1,
73 row2);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000074
75 /* Abort if we have only partial functionality */
76 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
77 && driver.getCharacterAtCursor && driver.clearWindow))
78 return;
Joseph Pranevichd87fa941999-01-03 16:15:12 +000079
80 /* Save initial state... */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000081 old_refresh = CONSOLE_GetRefresh();
82 CONSOLE_SetRefresh(FALSE);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000083 CONSOLE_GetCursorPosition(&trow, &tcol);
Joseph Pranevichd87fa941999-01-03 16:15:12 +000084
85 for (x = row1 + lines; x <= row2; x++)
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000086 {
Joseph Pranevichd87fa941999-01-03 16:15:12 +000087 GENERIC_MoveLine(x, x - lines, col1, col2);
88 GENERIC_ClearLine(x, col1, col2, bg_color, attribute);
89 }
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000090
Joseph Pranevichd87fa941999-01-03 16:15:12 +000091 /* Restore State */
92 CONSOLE_MoveCursor(trow, tcol);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000093 CONSOLE_SetRefresh(old_refresh);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +000094}
95
96void GENERIC_ScrollDownWindow(char row1, char col1, char row2, char col2,
97 char lines, int bg_color, int attribute)
98{
Joseph Pranevichd87fa941999-01-03 16:15:12 +000099 /* Scroll Down Window: Characters go up */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000100
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000101 char trow, tcol;
102 int old_refresh, x;
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000103
104 /* Abort if we have only partial functionality */
105 if (!(driver.getCursorPosition && driver.moveCursor && driver.write
106 && driver.getCharacterAtCursor && driver.clearWindow))
107 return;
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000108
109 /* Save initial state... */
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000110 old_refresh = CONSOLE_GetRefresh();
111 CONSOLE_SetRefresh(FALSE);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000112 CONSOLE_GetCursorPosition(&trow, &tcol);
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000113
114 for (x = row2; x >= row1 + lines; x--)
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000115 {
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000116 GENERIC_MoveLine(x, x + lines, col1, col2);
117 GENERIC_ClearLine(x, col1, col1, bg_color, attribute);
118 }
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000119
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000120 /* Restore State */
121 CONSOLE_MoveCursor(trow, tcol);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000122 CONSOLE_SetRefresh(old_refresh);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000123}
124
125char GENERIC_GetCharacter()
126{
127 /* Keep getting keys until we get one with a char value */
128 char ch = (char) 0, scan;
129
130 while (!ch)
131 {
Alexandre Julliard8da12c41999-01-17 16:55:11 +0000132 CONSOLE_GetKeystroke(&scan, &ch);
Joseph Pranevich791cd6a1998-12-02 19:58:08 +0000133 }
134 return ch;
135}
136
Joseph Pranevichd87fa941999-01-03 16:15:12 +0000137static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor,
138 int attribute)
139{
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 */
143
144 int x;
145
146 TRACE(console, "Clear Line: %d from %d to %d.\n", row, col1, col2);
147
148 for (x = col1; x <= col2; x++)
149 {
150 CONSOLE_MoveCursor(row, x);
151 CONSOLE_Write(' ', 0, 0, 0);
152 }
153
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. */
157}
158
159static void GENERIC_MoveLine(char row1, char row2, char col1, char col2)
160{
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 */
164
165 int x;
166 int bg_color, fg_color, attribute;
167 char ch;
168
169 TRACE(console, "Move Line: Move %d to %d.\n", row1, row2);
170
171 for (x = col1; x <= col2; x++)
172 {
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);
177 }
178
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. */
182}