Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 1999 - Joseph Pranevich |
| 3 | * |
| 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. |
| 8 | * |
| 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. |
| 13 | * |
| 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. |
| 18 | * |
| 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 |
| 22 | */ |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 23 | |
| 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 |
Andreas Mohr | a6d83eb | 2000-12-27 04:02:46 +0000 | [diff] [blame] | 26 | driver, it should make sure to preserve the old values. */ |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 27 | |
Francois Gouget | e5ddd26 | 2001-10-14 16:18:52 +0000 | [diff] [blame] | 28 | #include "config.h" |
| 29 | |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 30 | #include <stdio.h> |
Joseph Pranevich | 5576838 | 1998-12-09 15:43:03 +0000 | [diff] [blame] | 31 | |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 32 | #include "console.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 33 | #include "wine/debug.h" |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 34 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 35 | WINE_DEFAULT_DEBUG_CHANNEL(console); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 36 | |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 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, |
| 39 | int attribute); |
Eric Pouech | d57f7d1 | 2000-04-09 18:40:32 +0000 | [diff] [blame] | 40 | void GENERIC_Start(void) |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 41 | { |
| 42 | /* Here, we only want to add a driver if there is not one already |
| 43 | defined. */ |
| 44 | |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 45 | TRACE("GENERIC_Start\n"); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 46 | |
| 47 | if (!driver.clearWindow) |
| 48 | driver.clearWindow = GENERIC_ClearWindow; |
| 49 | |
| 50 | if (!driver.scrollUpWindow) |
| 51 | driver.scrollUpWindow = GENERIC_ScrollUpWindow; |
| 52 | |
| 53 | if (!driver.scrollDownWindow) |
| 54 | driver.scrollDownWindow = GENERIC_ScrollDownWindow; |
| 55 | |
| 56 | if (!driver.getCharacter) |
| 57 | driver.getCharacter = GENERIC_GetCharacter; |
| 58 | } |
| 59 | |
| 60 | void GENERIC_ClearWindow(char row1, char col1, char row2, char col2, |
| 61 | int bg_color, int attribute) |
| 62 | { |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 63 | char trow, tcol, x; |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 64 | int old_refresh; |
| 65 | |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 66 | /* Abort if we have only partial functionality */ |
| 67 | if (!(driver.getCursorPosition && driver.moveCursor && driver.write)) |
| 68 | return; |
| 69 | |
| 70 | old_refresh = CONSOLE_GetRefresh(); |
| 71 | CONSOLE_SetRefresh(FALSE); |
| 72 | |
| 73 | CONSOLE_GetCursorPosition(&trow, &tcol); |
| 74 | |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 75 | for (x = row1; x <= row2; x++) |
| 76 | GENERIC_ClearLine(x, col1, col2, bg_color, attribute); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 77 | |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 78 | CONSOLE_MoveCursor(trow, tcol); |
| 79 | |
| 80 | CONSOLE_SetRefresh(old_refresh); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 83 | void GENERIC_ScrollUpWindow(char row1, char col1, char row2, char col2, |
| 84 | char lines, int bg_color, int attribute) |
| 85 | { |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 86 | /* Scroll Up Window: Characters go down */ |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 87 | |
Patrik Stridvall | 2c68408 | 1999-07-31 17:36:48 +0000 | [diff] [blame] | 88 | char trow, tcol, x; |
| 89 | int old_refresh; |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 90 | |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 91 | TRACE("Scroll Up %d lines from %d to %d.\n", lines, row1, |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 92 | row2); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 93 | |
| 94 | /* Abort if we have only partial functionality */ |
| 95 | if (!(driver.getCursorPosition && driver.moveCursor && driver.write |
| 96 | && driver.getCharacterAtCursor && driver.clearWindow)) |
| 97 | return; |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 98 | |
| 99 | /* Save initial state... */ |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 100 | old_refresh = CONSOLE_GetRefresh(); |
| 101 | CONSOLE_SetRefresh(FALSE); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 102 | CONSOLE_GetCursorPosition(&trow, &tcol); |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 103 | |
| 104 | for (x = row1 + lines; x <= row2; x++) |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 105 | { |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 106 | GENERIC_MoveLine(x, x - lines, col1, col2); |
| 107 | GENERIC_ClearLine(x, col1, col2, bg_color, attribute); |
| 108 | } |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 109 | |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 110 | /* Restore State */ |
| 111 | CONSOLE_MoveCursor(trow, tcol); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 112 | CONSOLE_SetRefresh(old_refresh); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | void GENERIC_ScrollDownWindow(char row1, char col1, char row2, char col2, |
| 116 | char lines, int bg_color, int attribute) |
| 117 | { |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 118 | /* Scroll Down Window: Characters go up */ |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 119 | |
Patrik Stridvall | 2c68408 | 1999-07-31 17:36:48 +0000 | [diff] [blame] | 120 | char trow, tcol, x; |
| 121 | int old_refresh; |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 122 | |
| 123 | /* Abort if we have only partial functionality */ |
| 124 | if (!(driver.getCursorPosition && driver.moveCursor && driver.write |
| 125 | && driver.getCharacterAtCursor && driver.clearWindow)) |
| 126 | return; |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 127 | |
| 128 | /* Save initial state... */ |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 129 | old_refresh = CONSOLE_GetRefresh(); |
| 130 | CONSOLE_SetRefresh(FALSE); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 131 | CONSOLE_GetCursorPosition(&trow, &tcol); |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 132 | |
| 133 | for (x = row2; x >= row1 + lines; x--) |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 134 | { |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 135 | GENERIC_MoveLine(x, x + lines, col1, col2); |
| 136 | GENERIC_ClearLine(x, col1, col1, bg_color, attribute); |
| 137 | } |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 138 | |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 139 | /* Restore State */ |
| 140 | CONSOLE_MoveCursor(trow, tcol); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 141 | CONSOLE_SetRefresh(old_refresh); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | char GENERIC_GetCharacter() |
| 145 | { |
| 146 | /* Keep getting keys until we get one with a char value */ |
| 147 | char ch = (char) 0, scan; |
| 148 | |
| 149 | while (!ch) |
| 150 | { |
Alexandre Julliard | 8da12c4 | 1999-01-17 16:55:11 +0000 | [diff] [blame] | 151 | CONSOLE_GetKeystroke(&scan, &ch); |
Joseph Pranevich | 791cd6a | 1998-12-02 19:58:08 +0000 | [diff] [blame] | 152 | } |
| 153 | return ch; |
| 154 | } |
| 155 | |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 156 | static void GENERIC_ClearLine(char row, char col1, char col2, int bgcolor, |
| 157 | int attribute) |
| 158 | { |
| 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 */ |
| 162 | |
Patrik Stridvall | 2c68408 | 1999-07-31 17:36:48 +0000 | [diff] [blame] | 163 | char x; |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 164 | |
Joerg Mayer | abe635c | 2000-11-11 00:38:37 +0000 | [diff] [blame] | 165 | TRACE("Clear Line: %d from %d to %d (unused: bgcolor %d, attrib %d).\n", row, col1, col2, bgcolor, attribute); |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 166 | |
| 167 | for (x = col1; x <= col2; x++) |
| 168 | { |
| 169 | CONSOLE_MoveCursor(row, x); |
| 170 | CONSOLE_Write(' ', 0, 0, 0); |
| 171 | } |
| 172 | |
| 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 |
| 175 | changed. */ |
| 176 | } |
| 177 | |
| 178 | static void GENERIC_MoveLine(char row1, char row2, char col1, char col2) |
| 179 | { |
| 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 */ |
| 183 | |
Patrik Stridvall | 2c68408 | 1999-07-31 17:36:48 +0000 | [diff] [blame] | 184 | char x; |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 185 | int bg_color, fg_color, attribute; |
| 186 | char ch; |
| 187 | |
Alexandre Julliard | 9fe7a25 | 1999-05-14 08:17:14 +0000 | [diff] [blame] | 188 | TRACE("Move Line: Move %d to %d.\n", row1, row2); |
Joseph Pranevich | d87fa94 | 1999-01-03 16:15:12 +0000 | [diff] [blame] | 189 | |
| 190 | for (x = col1; x <= col2; x++) |
| 191 | { |
| 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); |
| 196 | } |
| 197 | |
| 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 |
| 200 | changed. */ |
| 201 | } |