Use 32-bit hook functions where possible. Cleaned up a couple of
[wine/multimedia.git] / console / interface.c
blob54fa41f150a038ae1c2b71cb9bcc5b6db0e362ec
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 CONSOLE_device driver;
20 static int pop_driver(char **, char **, int *);
22 static int console_initialized = FALSE;
24 static int CONSOLE_Init(void)
26 char buffer[256];
27 char *single, *drivers = buffer;
28 int length;
29 char initial_rows[5];
30 char initial_columns[5];
32 /* Suitable defaults... */
33 driver.console_out = stdout;
34 driver.console_in = stdin;
36 /* drivers should be a string that consists of driver names
37 followed by plus (+) signs to denote additions.
39 For example:
40 drivers = tty Load just the tty driver
41 drivers = ncurses+xterm Load ncurses then xterm
43 The "default" value is just tty.
45 PROFILE_GetWineIniString( "console", "Drivers", CONSOLE_DEFAULT_DRIVER,
46 buffer, sizeof(buffer) );
48 while (pop_driver(&drivers, &single, &length))
50 if (!strncmp(single, "tty", length))
51 TTY_Start();
52 #ifdef WINE_NCURSES
53 else if (!strncmp(single, "ncurses", length))
54 NCURSES_Start();
55 #endif /* WINE_NCURSES */
56 else if (!strncmp(single, "xterm", length))
57 XTERM_Start();
60 /* Read in generic configuration */
61 /* This is primarily to work around a limitation in nxterm where
62 this information is not correctly passed to the ncurses layer
63 through the terminal. At least, I'm not doing it correctly if there
64 is a way. But this serves as a generic way to do the same anyway. */
66 /* We are setting this to 80x25 here which is *not* the default for
67 most xterm variants... It is however the standard VGA resolution */
69 /* FIXME: We need to be able to be able to specify that the window's
70 dimensions should be used. This is required for correct emulation
71 of Win32's console and Win32's DOS emulation */
73 PROFILE_GetWineIniString("console", "InitialRows",
74 "24", initial_rows, 5);
75 PROFILE_GetWineIniString("console", "InitialColumns",
76 "80", initial_columns, 5);
78 sscanf(initial_rows, "%d", &driver.y_res);
79 sscanf(initial_columns, "%d", &driver.x_res);
81 GENERIC_Start();
83 if (driver.init)
84 driver.init();
86 /* Not all terminals let our programs know the proper resolution
87 if the resolution is set on the command-line... */
88 CONSOLE_NotifyResizeScreen(driver.x_res, driver.y_res);
90 atexit(CONSOLE_Close);
92 /* For now, always return TRUE */
93 return TRUE;
96 void CONSOLE_Write(char out, int fg_color, int bg_color, int attribute)
98 if (!console_initialized)
99 console_initialized = CONSOLE_Init();
101 if (driver.write)
103 driver.write(out, fg_color, bg_color, attribute);
104 if (!driver.norefresh)
105 CONSOLE_Refresh();
109 void CONSOLE_Close(void)
111 if (driver.close)
112 driver.close();
115 void CONSOLE_MoveCursor(char row, char col)
117 if (!console_initialized)
118 console_initialized = CONSOLE_Init();
120 if (driver.moveCursor)
122 driver.moveCursor(row, col);
123 if (!driver.norefresh)
124 CONSOLE_Refresh();
128 void CONSOLE_ClearWindow(char row1, char col1, char row2, char col2,
129 int bg_color, int attribute)
131 if (!console_initialized)
132 console_initialized = CONSOLE_Init();
134 if (driver.clearWindow)
136 driver.clearWindow(row1, col1, row2, col2, bg_color, attribute);
137 if (!driver.norefresh)
138 CONSOLE_Refresh();
142 void CONSOLE_ScrollUpWindow(char row1, char col1, char row2, char col2,
143 char lines, int bg_color, int attribute)
145 if (!console_initialized)
146 console_initialized = CONSOLE_Init();
148 if (driver.scrollUpWindow)
150 driver.scrollUpWindow(row1, col1, row2, col2, lines, bg_color,
151 attribute);
152 if (!driver.norefresh)
153 CONSOLE_Refresh();
157 void CONSOLE_ScrollDownWindow(char row1, char col1, char row2, char col2,
158 char lines, int bg_color, int attribute)
160 if (!console_initialized)
161 console_initialized = CONSOLE_Init();
163 if (driver.scrollDownWindow)
165 driver.scrollDownWindow(row1, col1, row2, col2, lines, bg_color,
166 attribute);
167 if (!driver.norefresh)
168 CONSOLE_Refresh();
172 int CONSOLE_CheckForKeystroke(char *scan, char *ascii)
173 /* These functions need to go through a conversion layer. Scancodes
174 should *not* be determined by the driver, rather they should have
175 a conv_* function in int16.c. Yuck. */
177 if (!console_initialized)
178 console_initialized = CONSOLE_Init();
180 if (driver.checkForKeystroke)
181 return driver.checkForKeystroke(scan, ascii);
182 else
183 return FALSE;
186 void CONSOLE_GetKeystroke(char *scan, char *ascii)
188 if (!console_initialized)
189 console_initialized = CONSOLE_Init();
191 if (driver.getKeystroke)
192 driver.getKeystroke(scan, ascii);
195 void CONSOLE_GetCursorPosition(char *row, char *col)
197 if (!console_initialized)
198 console_initialized = CONSOLE_Init();
200 if (driver.getCursorPosition)
201 driver.getCursorPosition(row, col);
204 void CONSOLE_GetCharacterAtCursor(char *ch, int *fg, int *bg, int *a)
206 if (!console_initialized)
207 console_initialized = CONSOLE_Init();
209 if (driver.getCharacterAtCursor)
210 driver.getCharacterAtCursor(ch, fg, bg, a);
213 void CONSOLE_Refresh()
215 if (!console_initialized)
216 console_initialized = CONSOLE_Init();
218 if (driver.refresh)
219 driver.refresh();
222 int CONSOLE_AllocColor(int color)
224 if (!console_initialized)
225 console_initialized = CONSOLE_Init();
227 if (driver.allocColor)
228 return driver.allocColor(color);
229 else
230 return 0;
233 void CONSOLE_ClearScreen()
235 if (!console_initialized)
236 console_initialized = CONSOLE_Init();
238 if (driver.clearScreen)
240 driver.clearScreen();
241 if (!driver.norefresh)
242 CONSOLE_Refresh();
246 char CONSOLE_GetCharacter()
248 if (!console_initialized)
249 console_initialized = CONSOLE_Init();
251 /* I'm not sure if we need this really. This is a function that can be
252 accelerated that returns the next *non extended* keystroke */
253 if (driver.getCharacter)
254 return driver.getCharacter();
255 else
256 return (char) 0; /* Sure, this will probably break programs... */
259 void CONSOLE_ResizeScreen(int x, int y)
261 if (!console_initialized)
262 console_initialized = CONSOLE_Init();
264 if (driver.resizeScreen)
265 driver.resizeScreen(x, y);
268 void CONSOLE_NotifyResizeScreen(int x, int y)
270 if (driver.notifyResizeScreen)
271 driver.notifyResizeScreen(x, y);
274 void CONSOLE_SetBackgroundColor(int fg, int bg)
276 if (!console_initialized)
277 console_initialized = CONSOLE_Init();
279 if (driver.setBackgroundColor)
280 driver.setBackgroundColor(fg, bg);
283 void CONSOLE_GetBackgroundColor(int *fg, int *bg)
285 if (!console_initialized)
286 console_initialized = CONSOLE_Init();
288 if (driver.getBackgroundColor)
289 driver.getBackgroundColor(fg, bg);
292 void CONSOLE_WriteRawString(char *str)
294 if (!console_initialized)
295 console_initialized = CONSOLE_Init();
297 /* This is a special function that is only for internal use and
298 does not actually call any of the console drivers. It's
299 primary purpose is to provide a way for higher-level drivers
300 to write directly to the underlying terminal without worry that
301 there will be any retranslation done by the assorted drivers. Care
302 should be taken to ensure that this only gets called when the thing
303 written does not actually produce any output or a CONSOLE_Redraw()
304 is called immediately afterwards.
305 CONSOLE_Redraw() is not yet implemented.
307 fprintf(driver.console_out, "%s", str);
310 /* This function is only at the CONSOLE level. */
311 /* Admittably, calling the variable norefresh might be a bit dumb...*/
312 void CONSOLE_SetRefresh(int setting)
314 if (setting)
315 driver.norefresh = FALSE;
316 else
317 driver.norefresh = TRUE;
320 /* This function is only at the CONSOLE level. */
321 int CONSOLE_GetRefresh()
323 if (driver.norefresh)
324 return FALSE;
325 else
326 return TRUE;
330 /* Utility functions... */
332 int pop_driver(char **drivers, char **single, int *length)
334 /* Take the string in drivers and extract the first "driver" entry */
335 /* Advance the pointer in drivers to the next entry, put the origional
336 pointer in single, and put the length in length. */
337 /* Return TRUE if we found one */
339 if (!*drivers)
340 return FALSE;
342 *single = *drivers;
343 *length = 0;
345 while ((*drivers[0] != '\0') && (*drivers[0] != '+'))
347 (*drivers)++;
348 (*length)++;
351 while (*drivers[0] == '+')
352 (*drivers)++;
354 if (*length)
355 return TRUE;
356 else
357 return FALSE;