Release 990225.
[wine/multimedia.git] / console / interface.c
blob515d9cccebdc2f9d46238296b255633a29e95985
1 /* interface.c */
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. */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #include "config.h"
14 #include "windef.h"
15 #include "console.h"
16 #include "options.h"
18 static int pop_driver(char **, char **, int *);
20 static int console_initialized = FALSE;
22 int CONSOLE_Init(char *drivers)
24 /* When this function is called drivers should be a string
25 that consists of driver names followed by plus (+) signs
26 to denote additions.
28 For example:
29 drivers = tty Load just the tty driver
30 drivers = ncurses+xterm Load ncurses then xterm
32 The "default" value is just tty.
35 char *single;
36 int length;
37 char initial_rows[5];
38 char initial_columns[5];
40 /* Suitable defaults... */
41 driver.console_out = stdout;
42 driver.console_in = stdin;
44 while (pop_driver(&drivers, &single, &length))
46 if (!strncmp(single, "tty", length))
47 TTY_Start();
48 #ifdef WINE_NCURSES
49 else if (!strncmp(single, "ncurses", length))
50 NCURSES_Start();
51 #endif /* WINE_NCURSES */
52 else if (!strncmp(single, "xterm", length))
53 XTERM_Start();
56 /* Read in generic configuration */
57 /* This is primarily to work around a limitation in nxterm where
58 this information is not correctly passed to the ncurses layer
59 through the terminal. At least, I'm not doing it correctly if there
60 is a way. But this serves as a generic way to do the same anyway. */
62 /* We are setting this to 80x25 here which is *not* the default for
63 most xterm variants... It is however the standard VGA resolution */
65 /* FIXME: We need to be able to be able to specify that the window's
66 dimensions should be used. This is required for correct emulation
67 of Win32's console and Win32's DOS emulation */
69 PROFILE_GetWineIniString("console", "InitialRows",
70 "24", initial_rows, 5);
71 PROFILE_GetWineIniString("console", "InitialColumns",
72 "80", initial_columns, 5);
74 sscanf(initial_rows, "%d", &driver.y_res);
75 sscanf(initial_columns, "%d", &driver.x_res);
77 GENERIC_Start();
79 if (driver.init)
80 driver.init();
82 /* Not all terminals let our programs know the proper resolution
83 if the resolution is set on the command-line... */
84 CONSOLE_NotifyResizeScreen(driver.x_res, driver.y_res);
86 /* For now, always return TRUE */
87 return TRUE;
90 void CONSOLE_Write(char out, int fg_color, int bg_color, int attribute)
92 if (!console_initialized)
93 console_initialized = CONSOLE_Init(driver.driver_list);
95 if (driver.write)
97 driver.write(out, fg_color, bg_color, attribute);
98 if (!driver.norefresh)
99 CONSOLE_Refresh();
103 void CONSOLE_Close()
105 if (driver.close)
106 driver.close();
109 void CONSOLE_MoveCursor(char row, char col)
111 if (!console_initialized)
112 console_initialized = CONSOLE_Init(driver.driver_list);
114 if (driver.moveCursor)
116 driver.moveCursor(row, col);
117 if (!driver.norefresh)
118 CONSOLE_Refresh();
122 void CONSOLE_ClearWindow(char row1, char col1, char row2, char col2,
123 int bg_color, int attribute)
125 if (!console_initialized)
126 console_initialized = CONSOLE_Init(driver.driver_list);
128 if (driver.clearWindow)
130 driver.clearWindow(row1, col1, row2, col2, bg_color, attribute);
131 if (!driver.norefresh)
132 CONSOLE_Refresh();
136 void CONSOLE_ScrollUpWindow(char row1, char col1, char row2, char col2,
137 char lines, int bg_color, int attribute)
139 if (!console_initialized)
140 console_initialized = CONSOLE_Init(driver.driver_list);
142 if (driver.scrollUpWindow)
144 driver.scrollUpWindow(row1, col1, row2, col2, lines, bg_color,
145 attribute);
146 if (!driver.norefresh)
147 CONSOLE_Refresh();
151 void CONSOLE_ScrollDownWindow(char row1, char col1, char row2, char col2,
152 char lines, int bg_color, int attribute)
154 if (!console_initialized)
155 console_initialized = CONSOLE_Init(driver.driver_list);
157 if (driver.scrollDownWindow)
159 driver.scrollDownWindow(row1, col1, row2, col2, lines, bg_color,
160 attribute);
161 if (!driver.norefresh)
162 CONSOLE_Refresh();
166 int CONSOLE_CheckForKeystroke(char *scan, char *ascii)
167 /* These functions need to go through a conversion layer. Scancodes
168 should *not* be determined by the driver, rather they should have
169 a conv_* function in int16.c. Yuck. */
171 if (!console_initialized)
172 console_initialized = CONSOLE_Init(driver.driver_list);
174 if (driver.checkForKeystroke)
175 return driver.checkForKeystroke(scan, ascii);
176 else
177 return FALSE;
180 void CONSOLE_GetKeystroke(char *scan, char *ascii)
182 if (!console_initialized)
183 console_initialized = CONSOLE_Init(driver.driver_list);
185 if (driver.getKeystroke)
186 driver.getKeystroke(scan, ascii);
189 void CONSOLE_GetCursorPosition(char *row, char *col)
191 if (!console_initialized)
192 console_initialized = CONSOLE_Init(driver.driver_list);
194 if (driver.getCursorPosition)
195 driver.getCursorPosition(row, col);
198 void CONSOLE_GetCharacterAtCursor(char *ch, int *fg, int *bg, int *a)
200 if (!console_initialized)
201 console_initialized = CONSOLE_Init(driver.driver_list);
203 if (driver.getCharacterAtCursor)
204 driver.getCharacterAtCursor(ch, fg, bg, a);
207 void CONSOLE_Refresh()
209 if (!console_initialized)
210 console_initialized = CONSOLE_Init(driver.driver_list);
212 if (driver.refresh)
213 driver.refresh();
216 int CONSOLE_AllocColor(int color)
218 if (!console_initialized)
219 console_initialized = CONSOLE_Init(driver.driver_list);
221 if (driver.allocColor)
222 return driver.allocColor(color);
223 else
224 return 0;
227 void CONSOLE_ClearScreen()
229 if (!console_initialized)
230 console_initialized = CONSOLE_Init(driver.driver_list);
232 if (driver.clearScreen)
234 driver.clearScreen();
235 if (!driver.norefresh)
236 CONSOLE_Refresh();
240 char CONSOLE_GetCharacter()
242 if (!console_initialized)
243 console_initialized = CONSOLE_Init(driver.driver_list);
245 /* I'm not sure if we need this really. This is a function that can be
246 accelerated that returns the next *non extended* keystroke */
247 if (driver.getCharacter)
248 return driver.getCharacter();
249 else
250 return (char) 0; /* Sure, this will probably break programs... */
253 void CONSOLE_ResizeScreen(int x, int y)
255 if (!console_initialized)
256 console_initialized = CONSOLE_Init(driver.driver_list);
258 if (driver.resizeScreen)
259 driver.resizeScreen(x, y);
262 void CONSOLE_NotifyResizeScreen(int x, int y)
264 if (driver.notifyResizeScreen)
265 driver.notifyResizeScreen(x, y);
268 void CONSOLE_SetBackgroundColor(int fg, int bg)
270 if (!console_initialized)
271 console_initialized = CONSOLE_Init(driver.driver_list);
273 if (driver.setBackgroundColor)
274 driver.setBackgroundColor(fg, bg);
277 void CONSOLE_GetBackgroundColor(int *fg, int *bg)
279 if (!console_initialized)
280 console_initialized = CONSOLE_Init(driver.driver_list);
282 if (driver.getBackgroundColor)
283 driver.getBackgroundColor(fg, bg);
286 void CONSOLE_WriteRawString(char *str)
288 if (!console_initialized)
289 console_initialized = CONSOLE_Init(driver.driver_list);
291 /* This is a special function that is only for internal use and
292 does not actually call any of the console drivers. It's
293 primary purpose is to provide a way for higher-level drivers
294 to write directly to the underlying terminal without worry that
295 there will be any retranslation done by the assorted drivers. Care
296 should be taken to ensure that this only gets called when the thing
297 written does not actually produce any output or a CONSOLE_Redraw()
298 is called immediately afterwards.
299 CONSOLE_Redraw() is not yet implemented.
301 fprintf(driver.console_out, "%s", str);
304 /* This function is only at the CONSOLE level. */
305 /* Admittably, calling the variable norefresh might be a bit dumb...*/
306 void CONSOLE_SetRefresh(int setting)
308 if (setting)
309 driver.norefresh = FALSE;
310 else
311 driver.norefresh = TRUE;
314 /* This function is only at the CONSOLE level. */
315 int CONSOLE_GetRefresh()
317 if (driver.norefresh)
318 return FALSE;
319 else
320 return TRUE;
324 /* Utility functions... */
326 int pop_driver(char **drivers, char **single, int *length)
328 /* Take the string in drivers and extract the first "driver" entry */
329 /* Advance the pointer in drivers to the next entry, put the origional
330 pointer in single, and put the length in length. */
331 /* Return TRUE if we found one */
333 if (!*drivers)
334 return FALSE;
336 *single = *drivers;
337 *length = 0;
339 while ((*drivers[0] != NULL) && (*drivers[0] != '+'))
341 (*drivers)++;
342 (*length)++;
345 while (*drivers[0] == '+')
346 (*drivers)++;
348 if (*length)
349 return TRUE;
350 else
351 return FALSE;