1 /* 2 * Copyright (c) 2002 by Michael J. Roberts. All Rights Reserved. 3 * 4 * Please see the accompanying license file, LICENSE.TXT, for information 5 * on using and copying this software. 6 */ 7 /* 8 Name 9 osgen.h - definitions for the osgen subsystem 10 Function 11 12 Notes 13 14 Modified 15 05/19/02 MJRoberts - Creation 16 */ 17 18 #ifndef OSGEN_H 19 #define OSGEN_H 20 21 /* ------------------------------------------------------------------------ */ 22 /* 23 * osgen support routines. These routines are implemented by the 24 * semi-portable osgen.c layer for use by the underlying osxxx code. 25 */ 26 27 /* 28 * Initialize the osgen scrollback buffer. Allocate the given amount of 29 * space in bytes for scrollback. 30 */ 31 void osssbini(unsigned int size); 32 33 /* 34 * Delete the scrollback buffer. This should be called during program 35 * termination to release memory allocated by osssbini(). 36 */ 37 void osssbdel(void); 38 39 40 /* 41 * The size, in character cells, of the ENTIRE SCREEN (or, at least, the 42 * entire part of the screen available for our use). Note that these 43 * variables reflect the size of the entire screen - these are NOT 44 * adjusted for status lines, banners, or anything else. 45 * 46 * The system-specific "oss" code MUST initialize these variables during 47 * startup, and MUST then keep them up to date whenever the screen size 48 * changes (for example, if we're running in a terminal window, and the 49 * user resizes the window, these must be updated to reflect the new 50 * window size). IN ADDITION, whenever the display size changes after 51 * start-up, the "oss" code MUST call osssb_on_resize_screen() to notify 52 * the osgen layer of the change. 53 * 54 * IMPORTANT: In the past, the "oss" code was responsible for initializing 55 * and maintaining the global variables G_os_linewidth and 56 * G_os_pagelength. The "oss" code need not do this any more - in fact, 57 * the OS code MUST STOP setting G_os_pagelength and G_os_linewidth. 58 * Change these variables instead. 59 */ 60 extern int G_oss_screen_width; 61 extern int G_oss_screen_height; 62 63 /* 64 * the "oss" code MUST call this routine whenever G_os_screen_width or 65 * G_os_screen_height change (except during initialization) 66 */ 67 void osssb_on_resize_screen(void); 68 69 #ifdef RUNTIME 70 71 /* 72 * Redraw the screen if necessary. The oss code MUST call this routine 73 * whenever it's going to pause for a timed wait, or stop to wait for user 74 * input. Specifically, this should be called from the OS implementation 75 * of the following routines: 76 * 77 * os_getc() 78 *. os_getc_raw() 79 *. os_waitc() 80 *. os_get_event() 81 *. os_askfile(); 82 *. os_input_dialog() 83 *. os_sleep_ms() 84 *. os_yield(); 85 */ 86 void osssb_redraw_if_needed(void); 87 88 /* 89 * Put the cursor at the default position. The oss code CAN optionally 90 * call this at the start of routines that pause for input to put the 91 * cursor at the default position in the main window. Depending on how the 92 * oss code implements text drawing, the osgen code can sometimes leave the 93 * cursor in a banner window rather than in the main window after drawing. 94 * This routine will ensure that the cursor is in the main window at the 95 * end of the main window's text. 96 */ 97 void osssb_cursor_to_default_pos(void); 98 99 #else /* RUNTIME */ 100 101 /* in non-RUNTIME mode, we don't use osssb_redraw_if_needed at all */ 102 #define osssb_redraw_if_needed() 103 104 /* in non-RUNTIME mode, we don't need to reposition the cursor */ 105 #define osssb_cursor_to_default_pos() 106 107 #endif /* RUNTIME */ 108 109 110 111 /* ------------------------------------------------------------------------ */ 112 /* 113 * ossxxx implementation for osgen. These routines must be defined by the 114 * OS-specific subsystem. 115 */ 116 117 /* 118 * Get extended system information. This checks to see if the ossxxx 119 * implementation handles the system information code. If the osxxx layer 120 * doesn't want to handle the code, it can return false so that the osgen 121 * layer will provide a default interpretation. 122 * 123 * Currently, the following codes should be handled by the oss layer: 124 * 125 * SYSINFO_TEXT_COLORS - return the level of color support on this 126 * platform. Because the ossxxx color interface that osgen uses is limited 127 * to the ANSI colors, this should normally return one of the ANSI support 128 * levels if color is supported, or the unsupported level if color isn't 129 * supported. Note that if the platform uses a fixed color scheme that 130 * cannot be controlled via the ossxxx routines, this should usually return 131 * the "highlighting only" or "parameterized colors" level. 132 * 133 * SYSINFO_TEXT_HILITE - indicate whether or not highlighted text is 134 * rendered in a distinctive appearance. 135 */ 136 int oss_get_sysinfo(int code, void *param, long *result); 137 138 /* 139 * Translate a portable color specification to an oss-style color code. 140 * This returns a color code suitable for use in ossclr(), ossdsp(), and 141 * the other ossxxx() routines defined here that take color codes as 142 * parameters; this color code is opaque to the caller. 143 * 144 * The purpose of this routine is to translate from the portable interface 145 * to color to the hardware-specific or OS-specific color coding used in 146 * the ossxxx layer, so that a caller given a color specified via the 147 * portable interface can send the appropriate ossxxx color code to the 148 * lower-level routines. 149 * 150 * 'fg', 'bg', and 'screen_color' are OSGEN_COLOR_xxx values. 'attrs' is a 151 * combination of OS_ATTR_xxx values (defined in osifc.h). This routine 152 * should combine the colors specified by the combination of these values 153 * to yield an appropriate color code for use in the ossxxx routines. 154 * 155 * Note that the 'bg' color can be OSGEN_COLOR_TRANSPARENT. If this is the 156 * case, the 'screen_color' value should be used to determine the 157 * background color, if possible. 'fg' should never be transparent. If 158 * 'bg' is not transparent, then screen color is usually ignored. 159 * 160 * COLOR SUPPORT IS OPTIONAL, but this routine must be implemented if 161 * osgen.c is to be used. If the platform does NOT support explicit color 162 * settings, this routine should still return an appropriate code that can 163 * be used with ossclr, etc. For example, the Unix oss implementation, at 164 * the time of this writing, used an internal color scheme to select from a 165 * fixed set of parameterized colors (normal, highlighted, reverse), so the 166 * Unix implementation could simply return its appropriate internal code, 167 * largely ignoring the requested colors. Note, however, that a platform 168 * with only parameterized colors might still want to inspect the 'fg' and 169 * 'bg' colors for the OSGEN_COLOR_xxx parameterized colors 170 * (OSGEN_COLOR_TEXT, OSGEN_COLOR_STATUSBG, etc), and return its internal 171 * code corresponding to the selected parameter color when possible. 172 */ 173 int ossgetcolor(int fg, int bg, int attrs, int screen_color); 174 175 /* 176 * Translate a key event from "raw" mode to processed mode. This takes an 177 * event of type OS_EVT_KEY, and converts the keystroke encoded in the 178 * event from the raw keystroke to a CMD_xxx code, if appropriate. 179 * 180 * In effect, this routine converts the event returned from os_get_event() 181 * to the corresponding command code that would be returned from os_getc(). 182 * 183 * This routine is defined at the "oss" level because the osgen layer is 184 * semi-portable, and thus needs to be aloof from the details of key 185 * mappings, which vary by system. 186 */ 187 void oss_raw_key_to_cmd(os_event_info_t *evt); 188 189 /* 190 * Clear an area of the screen. The color code is opaque to callers; it is 191 * meaningful only to the ossxxx implementation. 192 */ 193 void ossclr(int top, int left, int bottom, int right, int color); 194 195 /* 196 * Display text at a particular location in a particular color. 197 */ 198 void ossdsp(int line, int column, int color, const char *msg); 199 200 /* 201 * Move the cursor 202 */ 203 void ossloc(int line, int column); 204 205 /* 206 * Scroll a region of the screen UP one line. 207 */ 208 void ossscu(int top_line, int left_column, int bottom_line, 209 int right_column, int blank_color); 210 211 /* 212 * Scroll a region of the screen DOWN one line. 213 */ 214 void ossscr(int top_line, int left_column, int bottom_line, 215 int right_column, int blank_color); 216 217 218 /* ------------------------------------------------------------------------ */ 219 /* 220 * osgen attribute names - these are simply substitutes for the regular 221 * osifc attribute names; they map directly to the corresponding osifc 222 * attributes. 223 */ 224 #define OSGEN_ATTR_BOLD OS_ATTR_BOLD 225 226 227 /* ------------------------------------------------------------------------ */ 228 /* 229 * osgen colors. We don't use full RGB values in the osgen 230 * implementation, but use a simpler color scheme involving the 231 * parameterized colors (from the osifc layer), plus the eight ANSI colors 232 * (black, white, red, green, blue, yellow, cyan, magenta), each in a 233 * "low-intensity" and "high-intensity" version. 234 * 235 * If an underlying platform supports some colors but not all of the ANSI 236 * colors defined here, it should simply map each OSGEN_COLOR_xxx color to 237 * the closest available system color. 238 * 239 * Some systems use color intensity to render the "hilite" ("bold") 240 * attribute. On these systems, it's obviously not possible for the 241 * caller to select both boldness and the full range of colors 242 * independently, because that would leave no way to render bold text for 243 * the brighter half of the range of colors. Such systems should simply 244 * treat the high-intensity and low-intensity version of a given color as 245 * equivalent, and select the high- or low-intensity version according to 246 * the boldness attribute. For reference, here's the correspondence 247 * between the low- and high-intensity versions of the colors: 248 * 249 * low <-> high 250 *. black <-> gray 251 *. maroon <-> red 252 *. green <-> lime 253 *. navy <-> blue 254 *. teal <-> cyan 255 *. purple <-> magenta 256 *. olive <-> yellow 257 *. silver <-> white 258 * 259 * The comment for each absolute color gives the approximate RGB value we 260 * expect for the color (given as hex triplets on 00-FF intensity scale). 261 */ 262 263 /* the parameterized colors, mapped to single-byte values for osgen's use */ 264 #define OSGEN_COLOR_TRANSPARENT ((char)((OS_COLOR_P_TRANSPARENT) >> 24)) 265 #define OSGEN_COLOR_TEXT ((char)((OS_COLOR_P_TEXT) >> 24)) 266 #define OSGEN_COLOR_TEXTBG ((char)((OS_COLOR_P_TEXTBG) >> 24)) 267 #define OSGEN_COLOR_STATUSLINE ((char)((OS_COLOR_P_STATUSLINE) >> 24)) 268 #define OSGEN_COLOR_STATUSBG ((char)((OS_COLOR_P_STATUSBG) >> 24)) 269 #define OSGEN_COLOR_INPUT ((char)((OS_COLOR_P_INPUT) >> 24)) 270 271 /* "low-intensity" versions of the ANSI colors */ 272 #define OSGEN_COLOR_BLACK 0x70 /* 00 00 00 */ 273 #define OSGEN_COLOR_MAROON 0x71 /* 80 00 00 */ 274 #define OSGEN_COLOR_GREEN 0x72 /* 00 80 00 */ 275 #define OSGEN_COLOR_NAVY 0x73 /* 00 00 80 */ 276 #define OSGEN_COLOR_TEAL 0x74 /* 00 80 80 */ 277 #define OSGEN_COLOR_PURPLE 0x75 /* 80 00 80 */ 278 #define OSGEN_COLOR_OLIVE 0x76 /* 80 80 00 */ 279 #define OSGEN_COLOR_SILVER 0x77 /* C0 C0 C0 */ 280 281 /* "high-intensity" versions of the ANSI colors */ 282 #define OSGEN_COLOR_GRAY 0x78 /* 80 80 80 */ 283 #define OSGEN_COLOR_RED 0x79 /* FF 00 00 */ 284 #define OSGEN_COLOR_LIME 0x7A /* 00 FF 00 */ 285 #define OSGEN_COLOR_BLUE 0x7B /* 00 00 FF */ 286 #define OSGEN_COLOR_CYAN 0x7C /* 00 FF FF */ 287 #define OSGEN_COLOR_MAGENTA 0x7D /* FF 00 FF */ 288 #define OSGEN_COLOR_YELLOW 0x7E /* FF FF 00 */ 289 #define OSGEN_COLOR_WHITE 0x7F /* FF FF FF */ 290 291 #endif /* OSGEN_H */ 292