cfad47cfa3/tads2/osgen.h

4b825dc642cb6eb9a060e54bf8d69288fbee4904cfad47cfa334b206c65f22086bcc5d63e6f70944
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
/*
100
 *   Determine if stdin is at end-of-file.  If possible, this should return
101
 *   the stdin status even if we've never attempted to read stdin.
102
 *   
103
 *   For most Unix systems, this can return feof(stdin).  With some C
104
 *   libraries, however, this doesn't work until after an attempt has already
105
 *   been made to read from stdin, so we provide this cover to allow flexible
106
 *   implementation on different systems.  On Windows, for example, it's
107
 *   necessary to use _feof(_fileno(stdin)), because the higher-level feof()
108
 *   doesn't recognize EOF until the handle has been read from.  
109
 */
110
int oss_eof_on_stdin(void);
111
112
#else /* RUNTIME */
113
114
/* in non-RUNTIME mode, we don't use osssb_redraw_if_needed at all */
115
#define osssb_redraw_if_needed()
116
117
/* in non-RUNTIME mode, we don't need to reposition the cursor */
118
#define osssb_cursor_to_default_pos()
119
120
#endif /* RUNTIME */
121
122
123
124
/* ------------------------------------------------------------------------ */
125
/*
126
 *   ossxxx implementation for osgen.  These routines must be defined by the
127
 *   OS-specific subsystem. 
128
 */
129
130
/*
131
 *   Get extended system information.  This checks to see if the ossxxx
132
 *   implementation handles the system information code.  If the osxxx layer
133
 *   doesn't want to handle the code, it can return false so that the osgen
134
 *   layer will provide a default interpretation.
135
 *   
136
 *   Currently, the following codes should be handled by the oss layer:
137
 *   
138
 *   SYSINFO_TEXT_COLORS - return the level of color support on this
139
 *   platform.  Because the ossxxx color interface that osgen uses is limited
140
 *   to the ANSI colors, this should normally return one of the ANSI support
141
 *   levels if color is supported, or the unsupported level if color isn't
142
 *   supported.  Note that if the platform uses a fixed color scheme that
143
 *   cannot be controlled via the ossxxx routines, this should usually return
144
 *   the "highlighting only" or "parameterized colors" level.
145
 *   
146
 *   SYSINFO_TEXT_HILITE - indicate whether or not highlighted text is
147
 *   rendered in a distinctive appearance.  
148
 */
149
int oss_get_sysinfo(int code, void *param, long *result);
150
151
/*
152
 *   Translate a portable color specification to an oss-style color code.
153
 *   This returns a color code suitable for use in ossclr(), ossdsp(), and
154
 *   the other ossxxx() routines defined here that take color codes as
155
 *   parameters; this color code is opaque to the caller.
156
 *   
157
 *   The purpose of this routine is to translate from the portable interface
158
 *   to color to the hardware-specific or OS-specific color coding used in
159
 *   the ossxxx layer, so that a caller given a color specified via the
160
 *   portable interface can send the appropriate ossxxx color code to the
161
 *   lower-level routines.
162
 *   
163
 *   'fg', 'bg', and 'screen_color' are OSGEN_COLOR_xxx values.  'attrs' is a
164
 *   combination of OS_ATTR_xxx values (defined in osifc.h).  This routine
165
 *   should combine the colors specified by the combination of these values
166
 *   to yield an appropriate color code for use in the ossxxx routines.
167
 *   
168
 *   Note that the 'bg' color can be OSGEN_COLOR_TRANSPARENT.  If this is the
169
 *   case, the 'screen_color' value should be used to determine the
170
 *   background color, if possible.  'fg' should never be transparent.  If
171
 *   'bg' is not transparent, then screen color is usually ignored.
172
 *   
173
 *   COLOR SUPPORT IS OPTIONAL, but this routine must be implemented if
174
 *   osgen.c is to be used.  If the platform does NOT support explicit color
175
 *   settings, this routine should still return an appropriate code that can
176
 *   be used with ossclr, etc.  For example, the Unix oss implementation, at
177
 *   the time of this writing, used an internal color scheme to select from a
178
 *   fixed set of parameterized colors (normal, highlighted, reverse), so the
179
 *   Unix implementation could simply return its appropriate internal code,
180
 *   largely ignoring the requested colors.  Note, however, that a platform
181
 *   with only parameterized colors might still want to inspect the 'fg' and
182
 *   'bg' colors for the OSGEN_COLOR_xxx parameterized colors
183
 *   (OSGEN_COLOR_TEXT, OSGEN_COLOR_STATUSBG, etc), and return its internal
184
 *   code corresponding to the selected parameter color when possible.  
185
 */
186
int ossgetcolor(int fg, int bg, int attrs, int screen_color);
187
188
/*
189
 *   Translate a key event from "raw" mode to processed mode.  This takes an
190
 *   event of type OS_EVT_KEY, and converts the keystroke encoded in the
191
 *   event from the raw keystroke to a CMD_xxx code, if appropriate.
192
 *   
193
 *   In effect, this routine converts the event returned from os_get_event()
194
 *   to the corresponding command code that would be returned from os_getc().
195
 *   
196
 *   This routine is defined at the "oss" level because the osgen layer is
197
 *   semi-portable, and thus needs to be aloof from the details of key
198
 *   mappings, which vary by system.  
199
 */
200
void oss_raw_key_to_cmd(os_event_info_t *evt);
201
202
/*
203
 *   Clear an area of the screen.  The color code is opaque to callers; it is
204
 *   meaningful only to the ossxxx implementation.  
205
 */
206
void ossclr(int top, int left, int bottom, int right, int color);
207
208
/*
209
 *   Display text at a particular location in a particular color.
210
 */
211
void ossdsp(int line, int column, int color, const char *msg);
212
213
/*
214
 *   Move the cursor 
215
 */
216
void ossloc(int line, int column);
217
218
/*
219
 *   Scroll a region of the screen UP one line. 
220
 */
221
void ossscu(int top_line, int left_column, int bottom_line,
222
            int right_column, int blank_color);
223
224
/*
225
 *   Scroll a region of the screen DOWN one line. 
226
 */
227
void ossscr(int top_line, int left_column, int bottom_line,
228
            int right_column, int blank_color);
229
230
231
/* ------------------------------------------------------------------------ */
232
/*
233
 *   osgen attribute names - these are simply substitutes for the regular
234
 *   osifc attribute names; they map directly to the corresponding osifc
235
 *   attributes.  
236
 */
237
#define OSGEN_ATTR_BOLD OS_ATTR_BOLD
238
239
240
/* ------------------------------------------------------------------------ */
241
/*
242
 *   osgen colors.  We don't use full RGB values in the osgen
243
 *   implementation, but use a simpler color scheme involving the
244
 *   parameterized colors (from the osifc layer), plus the eight ANSI colors
245
 *   (black, white, red, green, blue, yellow, cyan, magenta), each in a
246
 *   "low-intensity" and "high-intensity" version.
247
 *   
248
 *   If an underlying platform supports some colors but not all of the ANSI
249
 *   colors defined here, it should simply map each OSGEN_COLOR_xxx color to
250
 *   the closest available system color.
251
 *   
252
 *   Some systems use color intensity to render the "hilite" ("bold")
253
 *   attribute.  On these systems, it's obviously not possible for the
254
 *   caller to select both boldness and the full range of colors
255
 *   independently, because that would leave no way to render bold text for
256
 *   the brighter half of the range of colors.  Such systems should simply
257
 *   treat the high-intensity and low-intensity version of a given color as
258
 *   equivalent, and select the high- or low-intensity version according to
259
 *   the boldness attribute.  For reference, here's the correspondence
260
 *   between the low- and high-intensity versions of the colors:
261
 *   
262
 *   low <-> high
263
 *.  black <-> gray
264
 *.  maroon <-> red
265
 *.  green <-> lime
266
 *.  navy <-> blue
267
 *.  teal <-> cyan
268
 *.  purple <-> magenta
269
 *.  olive <-> yellow
270
 *.  silver <-> white
271
 *   
272
 *   The comment for each absolute color gives the approximate RGB value we
273
 *   expect for the color (given as hex triplets on 00-FF intensity scale).  
274
 */
275
276
/* the parameterized colors, mapped to single-byte values for osgen's use */
277
#define OSGEN_COLOR_TRANSPARENT ((char)((OS_COLOR_P_TRANSPARENT) >> 24))
278
#define OSGEN_COLOR_TEXT        ((char)((OS_COLOR_P_TEXT) >> 24))
279
#define OSGEN_COLOR_TEXTBG      ((char)((OS_COLOR_P_TEXTBG) >> 24))
280
#define OSGEN_COLOR_STATUSLINE  ((char)((OS_COLOR_P_STATUSLINE) >> 24))
281
#define OSGEN_COLOR_STATUSBG    ((char)((OS_COLOR_P_STATUSBG) >> 24))
282
#define OSGEN_COLOR_INPUT       ((char)((OS_COLOR_P_INPUT) >> 24))
283
284
/* "low-intensity" versions of the ANSI colors */
285
#define OSGEN_COLOR_BLACK       0x70                            /* 00 00 00 */
286
#define OSGEN_COLOR_MAROON      0x71                            /* 80 00 00 */
287
#define OSGEN_COLOR_GREEN       0x72                            /* 00 80 00 */
288
#define OSGEN_COLOR_NAVY        0x73                            /* 00 00 80 */
289
#define OSGEN_COLOR_TEAL        0x74                            /* 00 80 80 */
290
#define OSGEN_COLOR_PURPLE      0x75                            /* 80 00 80 */
291
#define OSGEN_COLOR_OLIVE       0x76                            /* 80 80 00 */
292
#define OSGEN_COLOR_SILVER      0x77                            /* C0 C0 C0 */
293
294
/* "high-intensity" versions of the ANSI colors */
295
#define OSGEN_COLOR_GRAY        0x78                            /* 80 80 80 */
296
#define OSGEN_COLOR_RED         0x79                            /* FF 00 00 */
297
#define OSGEN_COLOR_LIME        0x7A                            /* 00 FF 00 */
298
#define OSGEN_COLOR_BLUE        0x7B                            /* 00 00 FF */
299
#define OSGEN_COLOR_CYAN        0x7C                            /* 00 FF FF */
300
#define OSGEN_COLOR_MAGENTA     0x7D                            /* FF 00 FF */
301
#define OSGEN_COLOR_YELLOW      0x7E                            /* FF FF 00 */
302
#define OSGEN_COLOR_WHITE       0x7F                            /* FF FF FF */
303
304
#endif /* OSGEN_H */