3 /* The primary purpose of this function is to provide CONSOLE_*
4 reotines that immediately call the appropiate driver handler.
5 This cleans up code in the individual modules considerably.
6 This could be done using a macro, but additional functionality
7 may be provided here in the future. */
18 CONSOLE_device driver
;
20 static int pop_driver(char **, char **, int *);
22 static int console_initialized
= FALSE
;
24 int CONSOLE_Init(char *drivers
)
26 /* When this function is called drivers should be a string
27 that consists of driver names followed by plus (+) signs
31 drivers = tty Load just the tty driver
32 drivers = ncurses+xterm Load ncurses then xterm
34 The "default" value is just tty.
40 char initial_columns
[5];
42 /* Suitable defaults... */
43 driver
.console_out
= stdout
;
44 driver
.console_in
= stdin
;
46 while (pop_driver(&drivers
, &single
, &length
))
48 if (!strncmp(single
, "tty", length
))
51 else if (!strncmp(single
, "ncurses", length
))
53 #endif /* WINE_NCURSES */
54 else if (!strncmp(single
, "xterm", length
))
58 /* Read in generic configuration */
59 /* This is primarily to work around a limitation in nxterm where
60 this information is not correctly passed to the ncurses layer
61 through the terminal. At least, I'm not doing it correctly if there
62 is a way. But this serves as a generic way to do the same anyway. */
64 /* We are setting this to 80x25 here which is *not* the default for
65 most xterm variants... It is however the standard VGA resolution */
67 /* FIXME: We need to be able to be able to specify that the window's
68 dimensions should be used. This is required for correct emulation
69 of Win32's console and Win32's DOS emulation */
71 PROFILE_GetWineIniString("console", "InitialRows",
72 "24", initial_rows
, 5);
73 PROFILE_GetWineIniString("console", "InitialColumns",
74 "80", initial_columns
, 5);
76 sscanf(initial_rows
, "%d", &driver
.y_res
);
77 sscanf(initial_columns
, "%d", &driver
.x_res
);
84 /* Not all terminals let our programs know the proper resolution
85 if the resolution is set on the command-line... */
86 CONSOLE_NotifyResizeScreen(driver
.x_res
, driver
.y_res
);
88 /* For now, always return TRUE */
92 void CONSOLE_Write(char out
, int fg_color
, int bg_color
, int attribute
)
94 if (!console_initialized
)
95 console_initialized
= CONSOLE_Init(driver
.driver_list
);
99 driver
.write(out
, fg_color
, bg_color
, attribute
);
100 if (!driver
.norefresh
)
111 void CONSOLE_MoveCursor(char row
, char col
)
113 if (!console_initialized
)
114 console_initialized
= CONSOLE_Init(driver
.driver_list
);
116 if (driver
.moveCursor
)
118 driver
.moveCursor(row
, col
);
119 if (!driver
.norefresh
)
124 void CONSOLE_ClearWindow(char row1
, char col1
, char row2
, char col2
,
125 int bg_color
, int attribute
)
127 if (!console_initialized
)
128 console_initialized
= CONSOLE_Init(driver
.driver_list
);
130 if (driver
.clearWindow
)
132 driver
.clearWindow(row1
, col1
, row2
, col2
, bg_color
, attribute
);
133 if (!driver
.norefresh
)
138 void CONSOLE_ScrollUpWindow(char row1
, char col1
, char row2
, char col2
,
139 char lines
, int bg_color
, int attribute
)
141 if (!console_initialized
)
142 console_initialized
= CONSOLE_Init(driver
.driver_list
);
144 if (driver
.scrollUpWindow
)
146 driver
.scrollUpWindow(row1
, col1
, row2
, col2
, lines
, bg_color
,
148 if (!driver
.norefresh
)
153 void CONSOLE_ScrollDownWindow(char row1
, char col1
, char row2
, char col2
,
154 char lines
, int bg_color
, int attribute
)
156 if (!console_initialized
)
157 console_initialized
= CONSOLE_Init(driver
.driver_list
);
159 if (driver
.scrollDownWindow
)
161 driver
.scrollDownWindow(row1
, col1
, row2
, col2
, lines
, bg_color
,
163 if (!driver
.norefresh
)
168 int CONSOLE_CheckForKeystroke(char *scan
, char *ascii
)
169 /* These functions need to go through a conversion layer. Scancodes
170 should *not* be determined by the driver, rather they should have
171 a conv_* function in int16.c. Yuck. */
173 if (!console_initialized
)
174 console_initialized
= CONSOLE_Init(driver
.driver_list
);
176 if (driver
.checkForKeystroke
)
177 return driver
.checkForKeystroke(scan
, ascii
);
182 void CONSOLE_GetKeystroke(char *scan
, char *ascii
)
184 if (!console_initialized
)
185 console_initialized
= CONSOLE_Init(driver
.driver_list
);
187 if (driver
.getKeystroke
)
188 driver
.getKeystroke(scan
, ascii
);
191 void CONSOLE_GetCursorPosition(char *row
, char *col
)
193 if (!console_initialized
)
194 console_initialized
= CONSOLE_Init(driver
.driver_list
);
196 if (driver
.getCursorPosition
)
197 driver
.getCursorPosition(row
, col
);
200 void CONSOLE_GetCharacterAtCursor(char *ch
, int *fg
, int *bg
, int *a
)
202 if (!console_initialized
)
203 console_initialized
= CONSOLE_Init(driver
.driver_list
);
205 if (driver
.getCharacterAtCursor
)
206 driver
.getCharacterAtCursor(ch
, fg
, bg
, a
);
209 void CONSOLE_Refresh()
211 if (!console_initialized
)
212 console_initialized
= CONSOLE_Init(driver
.driver_list
);
218 int CONSOLE_AllocColor(int color
)
220 if (!console_initialized
)
221 console_initialized
= CONSOLE_Init(driver
.driver_list
);
223 if (driver
.allocColor
)
224 return driver
.allocColor(color
);
229 void CONSOLE_ClearScreen()
231 if (!console_initialized
)
232 console_initialized
= CONSOLE_Init(driver
.driver_list
);
234 if (driver
.clearScreen
)
236 driver
.clearScreen();
237 if (!driver
.norefresh
)
242 char CONSOLE_GetCharacter()
244 if (!console_initialized
)
245 console_initialized
= CONSOLE_Init(driver
.driver_list
);
247 /* I'm not sure if we need this really. This is a function that can be
248 accelerated that returns the next *non extended* keystroke */
249 if (driver
.getCharacter
)
250 return driver
.getCharacter();
252 return (char) 0; /* Sure, this will probably break programs... */
255 void CONSOLE_ResizeScreen(int x
, int y
)
257 if (!console_initialized
)
258 console_initialized
= CONSOLE_Init(driver
.driver_list
);
260 if (driver
.resizeScreen
)
261 driver
.resizeScreen(x
, y
);
264 void CONSOLE_NotifyResizeScreen(int x
, int y
)
266 if (driver
.notifyResizeScreen
)
267 driver
.notifyResizeScreen(x
, y
);
270 void CONSOLE_SetBackgroundColor(int fg
, int bg
)
272 if (!console_initialized
)
273 console_initialized
= CONSOLE_Init(driver
.driver_list
);
275 if (driver
.setBackgroundColor
)
276 driver
.setBackgroundColor(fg
, bg
);
279 void CONSOLE_GetBackgroundColor(int *fg
, int *bg
)
281 if (!console_initialized
)
282 console_initialized
= CONSOLE_Init(driver
.driver_list
);
284 if (driver
.getBackgroundColor
)
285 driver
.getBackgroundColor(fg
, bg
);
288 void CONSOLE_WriteRawString(char *str
)
290 if (!console_initialized
)
291 console_initialized
= CONSOLE_Init(driver
.driver_list
);
293 /* This is a special function that is only for internal use and
294 does not actually call any of the console drivers. It's
295 primary purpose is to provide a way for higher-level drivers
296 to write directly to the underlying terminal without worry that
297 there will be any retranslation done by the assorted drivers. Care
298 should be taken to ensure that this only gets called when the thing
299 written does not actually produce any output or a CONSOLE_Redraw()
300 is called immediately afterwards.
301 CONSOLE_Redraw() is not yet implemented.
303 fprintf(driver
.console_out
, "%s", str
);
306 /* This function is only at the CONSOLE level. */
307 /* Admittably, calling the variable norefresh might be a bit dumb...*/
308 void CONSOLE_SetRefresh(int setting
)
311 driver
.norefresh
= FALSE
;
313 driver
.norefresh
= TRUE
;
316 /* This function is only at the CONSOLE level. */
317 int CONSOLE_GetRefresh()
319 if (driver
.norefresh
)
326 /* Utility functions... */
328 int pop_driver(char **drivers
, char **single
, int *length
)
330 /* Take the string in drivers and extract the first "driver" entry */
331 /* Advance the pointer in drivers to the next entry, put the origional
332 pointer in single, and put the length in length. */
333 /* Return TRUE if we found one */
341 while ((*drivers
[0] != NULL
) && (*drivers
[0] != '+'))
347 while (*drivers
[0] == '+')