1 /* $Id: console.c,v 1.18 2003-11-26 12:39:00 btb Exp $ */
4 * Code for controlling the console
24 #include "CON_console.h"
39 int text_console_enabled = 1;
42 #define text_console_enabled (!isvga())
47 /* Console specific cvars */
48 /* How discriminating we are about which messages are displayed */
49 cvar_t con_threshold = {"con_threshold", "0",};
51 /* Private console stuff */
52 #define CON_NUM_LINES 40
54 #define CON_LINE_LEN 40
55 static char con_display[40][40];
56 static int con_line; /* Current display line */
60 static int con_initialized;
62 ConsoleInformation *Console;
64 void con_parse(ConsoleInformation *console, char *command);
68 /* Free the console */
78 /* Initialise the console */
81 grs_screen fake_screen;
84 fake_screen.sc_w = 320;
85 fake_screen.sc_h = 200;
89 Console = CON_Init(&fake_font, &fake_screen, CON_NUM_LINES, 0, 0, 320, 200);
91 CON_SetExecuteFunction(Console, con_parse);
92 CON_SetHideFunction(Console, con_hide);
97 /* Initialise the cvars */
98 cvar_registervariable (&con_threshold);
107 #define CON_BG_HIRES (cfexist("scoresb.pcx")?"scoresb.pcx":"scores.pcx")
108 #define CON_BG_LORES (cfexist("scores.pcx")?"scores.pcx":"scoresb.pcx") // Mac datafiles only have scoresb.pcx
109 #define CON_BG ((SWIDTH>=640)?CON_BG_HIRES:CON_BG_LORES)
111 void con_background(char *filename)
117 gr_init_bitmap_data(&bmp);
118 pcx_error = pcx_read_bitmap(filename, &bmp, BM_LINEAR, pal);
119 Assert(pcx_error == PCX_ERROR_NONE);
120 gr_remap_bitmap_good(&bmp, pal, -1, -1);
121 CON_Background(Console, &bmp);
122 gr_free_bitmap_data(&bmp);
126 void con_init_gfx(void)
128 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
129 CON_Transfer(Console, grd_curscreen, 0, 0, SWIDTH, SHEIGHT / 2);
131 con_background(CON_BG);
136 void con_resize(void)
139 CON_Font(Console, SMALL_FONT, gr_getcolor(63, 63, 63), -1);
140 CON_Resize(Console, 0, 0, SWIDTH, SHEIGHT / 2);
141 con_background(CON_BG);
145 /* Print a message to the console */
146 void con_printf(int priority, char *fmt, ...)
151 if (priority <= ((int)con_threshold.value))
153 va_start (arglist, fmt);
154 vsprintf (buffer, fmt, arglist);
159 CON_Out(Console, buffer);
162 /* for (i=0; i<l; i+=CON_LINE_LEN,con_line++)
164 memcpy(con_display, &buffer[i], min(80, l-i));
167 if (text_console_enabled)
169 /* Produce a sanitised version and send it to the standard output */
188 printf("%s", buffer);
193 /* Check for new console input. If it's there, use it */
194 void con_update(void)
197 char buffer[CMD_MAX_LENGTH], *t;
199 /* Check for new input */
200 t = fgets(buffer, sizeof(buffer), stdin);
201 if (t == NULL) return;
209 int con_events(int key)
212 return CON_Events(key);
219 /* Draw the console */
223 CON_DrawConsole(Console);
226 char buffer[CON_LINE_LEN+1];
228 for (i = con_line, j=0; j < 20; i = (i+1) % CON_NUM_LINES, j++)
230 memcpy(buffer, con_display[i], CON_LINE_LEN);
231 buffer[CON_LINE_LEN] = 0;
232 gr_string(1,j*10,buffer);
238 /* Show the console */
244 CON_Topmost(Console);
254 void con_parse(ConsoleInformation *console, char *command)