Playing a non-existent CD should fail instead of crash.
[wine/multimedia.git] / console / interface.c
blob252350d5aefc4fa66e9f90166564d5f46148ba94
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 "windows.h"
14 #include "console.h"
15 #include "config.h"
17 static int pop_driver(char **, char **, int *);
19 void CONSOLE_Write(char out, int fg_color, int bg_color, int attribute)
21 if (driver.write)
23 driver.write(out, fg_color, bg_color, attribute);
24 if (!driver.norefresh)
25 CONSOLE_Refresh();
29 void CONSOLE_Init(char *drivers)
31 /* When this function is called drivers should be a string
32 that consists of driver names followed by plus (+) signs
33 to denote additions.
35 For example:
36 drivers = tty Load just the tty driver
37 drivers = ncurses+xterm Load ncurses then xterm
39 The "default" value is just tty.
42 char *single;
43 int length;
45 /* Suitable defaults... */
46 driver.console_out = stdout;
47 driver.console_in = stdin;
49 while (pop_driver(&drivers, &single, &length))
51 if (!strncmp(single, "tty", length))
52 TTY_Start();
53 #ifdef WINE_NCURSES
54 else if (!strncmp(single, "ncurses", length))
55 NCURSES_Start();
56 #endif /* WINE_NCURSES */
57 else if (!strncmp(single, "xterm", length))
58 XTERM_Start();
61 GENERIC_Start();
63 if (driver.init)
64 driver.init();
67 void CONSOLE_Close()
69 if (driver.close)
70 driver.close();
73 void CONSOLE_MoveCursor(char row, char col)
75 if (driver.moveCursor)
77 driver.moveCursor(row, col);
78 if (!driver.norefresh)
79 CONSOLE_Refresh();
83 void CONSOLE_ClearWindow(char row1, char col1, char row2, char col2,
84 int bg_color, int attribute)
86 if (driver.clearWindow)
88 driver.clearWindow(row1, col1, row2, col2, bg_color, attribute);
89 if (!driver.norefresh)
90 CONSOLE_Refresh();
94 void CONSOLE_ScrollUpWindow(char row1, char col1, char row2, char col2,
95 char lines, int bg_color, int attribute)
97 if (driver.scrollUpWindow)
99 driver.scrollUpWindow(row1, col1, row2, col2, lines, bg_color,
100 attribute);
101 if (!driver.norefresh)
102 CONSOLE_Refresh();
106 void CONSOLE_ScrollDownWindow(char row1, char col1, char row2, char col2,
107 char lines, int bg_color, int attribute)
109 if (driver.scrollDownWindow)
111 driver.scrollDownWindow(row1, col1, row2, col2, lines, bg_color,
112 attribute);
113 if (!driver.norefresh)
114 CONSOLE_Refresh();
118 int CONSOLE_CheckForKeystroke(char *scan, char *ascii)
119 /* These functions need to go through a conversion layer. Scancodes
120 should *not* be determined by the driver, rather they should have
121 a conv_* function in int16.c. Yuck. */
123 if (driver.checkForKeystroke)
124 return driver.checkForKeystroke(scan, ascii);
125 else
126 return FALSE;
129 void CONSOLE_GetKeystroke(char *scan, char *ascii)
131 if (driver.getKeystroke)
132 driver.getKeystroke(scan, ascii);
135 void CONSOLE_GetCursorPosition(char *row, char *col)
137 if (driver.getCursorPosition)
138 driver.getCursorPosition(row, col);
141 void CONSOLE_GetCharacterAtCursor(char *ch, int *fg, int *bg, int *a)
143 if (driver.getCharacterAtCursor)
144 driver.getCharacterAtCursor(ch, fg, bg, a);
147 void CONSOLE_Refresh()
149 if (driver.refresh)
150 driver.refresh();
153 /* This function is only at the CONSOLE level. */
154 /* Admittably, calling the variable norefresh might be a bit dumb...*/
155 void CONSOLE_SetRefresh(int setting)
157 if (setting)
158 driver.norefresh = FALSE;
159 else
160 driver.norefresh = TRUE;
163 /* This function is only at the CONSOLE level. */
164 int CONSOLE_GetRefresh()
166 if (driver.norefresh)
167 return FALSE;
168 else
169 return TRUE;
172 void CONSOLE_ClearScreen()
174 if (driver.clearScreen)
176 driver.clearScreen();
177 if (!driver.norefresh)
178 CONSOLE_Refresh();
182 char CONSOLE_GetCharacter()
184 /* I'm not sure if we need this really. This is a function that can be
185 accelerated that returns the next *non extended* keystroke */
186 if (driver.getCharacter)
187 return driver.getCharacter();
188 else
189 return (char) 0; /* Sure, this will probably break programs... */
192 void CONSOLE_ResizeScreen(int x, int y)
194 if (driver.resizeScreen)
195 driver.resizeScreen(x, y);
198 void CONSOLE_NotifyResizeScreen(int x, int y)
200 if (driver.resizeScreen)
201 driver.resizeScreen(x, y);
204 /* Utility functions... */
206 int pop_driver(char **drivers, char **single, int *length)
208 /* Take the string in drivers and extract the first "driver" entry */
209 /* Advance the pointer in drivers to the next entry, put the origional
210 pointer in single, and put the length in length. */
211 /* Return TRUE if we found one */
213 if (!*drivers)
214 return FALSE;
216 *single = *drivers;
217 *length = 0;
219 while ((*drivers[0] != NULL) && (*drivers[0] != '+'))
221 (*drivers)++;
222 (*length)++;
225 while (*drivers[0] == '+')
226 (*drivers)++;
228 if (*length)
229 return TRUE;
230 else
231 return FALSE;