2006-04-13 20:47:06 +00:00
|
|
|
// On-screen display (ie. console)
|
|
|
|
// for the Build Engine
|
2012-03-12 04:47:04 +00:00
|
|
|
// by Jonathon Fowler (jf@jonof.id.au)
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
#ifndef __osd_h__
|
|
|
|
#define __osd_h__
|
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
#ifdef EXTERNC
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
#include "mutex.h"
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
typedef struct {
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t numparms;
|
2006-04-13 20:47:06 +00:00
|
|
|
const char *name;
|
|
|
|
const char **parms;
|
|
|
|
const char *raw;
|
|
|
|
} osdfuncparm_t;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
const char *OSD_StripColors(char *out, const char *in);
|
2008-06-30 00:18:59 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
#define OSDDEFAULTMAXLINES 128
|
|
|
|
#define OSDEDITLENGTH 512
|
|
|
|
#define OSDMINHISTORYDEPTH 32
|
|
|
|
#define OSDMAXHISTORYDEPTH 256
|
|
|
|
#define OSDBUFFERSIZE 32768
|
|
|
|
#define OSDDEFAULTROWS 20
|
|
|
|
#define OSDDEFAULTCOLS 60
|
|
|
|
#define OSDLOGCUTOFF 131072
|
|
|
|
#define OSDMAXSYMBOLS 512
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
enum cvartype_t
|
2009-04-29 06:20:07 +00:00
|
|
|
{
|
2013-05-15 02:16:19 +00:00
|
|
|
CVAR_FLOAT = 0x00000001,
|
|
|
|
CVAR_INT = 0x00000002,
|
|
|
|
CVAR_UINT = 0x00000004,
|
|
|
|
CVAR_BOOL = 0x00000008,
|
|
|
|
CVAR_STRING = 0x00000010,
|
|
|
|
CVAR_DOUBLE = 0x00000020,
|
|
|
|
CVAR_LOCKED = 0x00000040,
|
|
|
|
CVAR_MULTI = 0x00000080,
|
|
|
|
CVAR_NOSAVE = 0x00000100,
|
|
|
|
CVAR_FUNCPTR = 0x00000200,
|
|
|
|
CVAR_RESTARTVID = 0x00000400,
|
2013-05-15 02:17:17 +00:00
|
|
|
CVAR_INVALIDATEALL = 0x00000800,
|
|
|
|
CVAR_INVALIDATEART = 0x00001000,
|
2009-04-29 06:20:07 +00:00
|
|
|
};
|
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
typedef struct _symbol
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
struct _symbol *next;
|
|
|
|
|
|
|
|
const char *help;
|
|
|
|
int32_t(*func)(const osdfuncparm_t *);
|
|
|
|
} symbol_t;
|
|
|
|
|
2009-04-29 06:20:07 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2011-02-21 23:08:21 +00:00
|
|
|
const char *name;
|
2011-04-07 01:16:29 +00:00
|
|
|
const char *desc;
|
2012-12-31 01:51:03 +00:00
|
|
|
void *vptr;
|
2010-06-07 09:03:16 +00:00
|
|
|
int32_t type; // see cvartype_t
|
2009-04-29 06:20:07 +00:00
|
|
|
int32_t min;
|
2010-06-07 09:03:16 +00:00
|
|
|
int32_t max; // for string, is the length
|
2009-04-29 06:20:07 +00:00
|
|
|
} cvar_t;
|
|
|
|
|
2010-06-07 09:03:16 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2012-12-31 01:51:03 +00:00
|
|
|
cvar_t c;
|
2010-06-07 09:03:16 +00:00
|
|
|
|
|
|
|
// default value for cvar, assigned when var is registered
|
|
|
|
union
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
uint32_t uint;
|
|
|
|
float f;
|
|
|
|
double d;
|
|
|
|
} dval;
|
|
|
|
} osdcvar_t;
|
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
// version string
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
|
|
|
|
uint8_t len;
|
|
|
|
uint8_t shade;
|
|
|
|
uint8_t pal;
|
|
|
|
} osdstr_t;
|
|
|
|
|
|
|
|
// command prompt editing
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *buf;// [OSDEDITLENGTH+1]; // editing buffer
|
|
|
|
char *tmp;// [OSDEDITLENGTH+1]; // editing buffer temporary workspace
|
|
|
|
|
|
|
|
int16_t len, pos; // length of characters and position of cursor in buffer
|
|
|
|
int16_t start, end;
|
|
|
|
} osdedit_t;
|
|
|
|
|
|
|
|
// main text buffer
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
// each character in the buffer also has a format byte containing shade and color
|
|
|
|
char *buf;
|
|
|
|
char *fmt;
|
|
|
|
|
|
|
|
int32_t pos; // position next character will be written at
|
|
|
|
int32_t lines; // total number of lines in buffer
|
|
|
|
int32_t maxlines; // max lines in buffer
|
|
|
|
} osdtext_t;
|
|
|
|
|
|
|
|
// history display
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *buf[OSDMAXHISTORYDEPTH];
|
|
|
|
|
|
|
|
int32_t maxlines; // max entries in buffer, ranges from OSDMINHISTORYDEPTH to OSDMAXHISTORYDEPTH
|
|
|
|
int32_t pos; // current buffer position
|
|
|
|
int32_t lines; // entries currently in buffer
|
|
|
|
int32_t total; // total number of entries
|
|
|
|
int32_t exec; // number of lines from the head of the history buffer to execute
|
|
|
|
} osdhist_t;
|
|
|
|
|
|
|
|
// active display parameters
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
int32_t promptshade, promptpal;
|
|
|
|
int32_t editshade, editpal;
|
|
|
|
int32_t textshade, textpal;
|
|
|
|
int32_t mode;
|
|
|
|
|
|
|
|
int32_t rows; // # lines of the buffer that are visible
|
|
|
|
int32_t cols; // width of onscreen display in text columns
|
|
|
|
int32_t head; // topmost visible line number
|
|
|
|
} osddraw_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BFILE *fp;
|
|
|
|
int32_t cutoff;
|
|
|
|
int32_t errors;
|
|
|
|
int32_t lines;
|
|
|
|
} osdlog_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
osdtext_t text;
|
|
|
|
osdedit_t editor;
|
|
|
|
osdhist_t history;
|
|
|
|
osddraw_t draw;
|
|
|
|
osdstr_t verstr;
|
|
|
|
|
|
|
|
uint32_t flags; // controls initialization, etc
|
|
|
|
osdcvar_t *cvars;
|
|
|
|
uint32_t numcvars;
|
|
|
|
|
|
|
|
symbol_t *symbptrs[OSDMAXSYMBOLS];
|
|
|
|
int32_t numsymbols;
|
|
|
|
int32_t execdepth; // keeps track of nested execution
|
|
|
|
mutex_t mutex;
|
|
|
|
int32_t keycode;
|
|
|
|
|
|
|
|
osdlog_t log;
|
|
|
|
} osdmain_t;
|
|
|
|
|
|
|
|
extern osdmain_t *osd;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
enum osdflags_t
|
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
// OSD_INITIALIZED = 0x00000001,
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_DRAW = 0x00000002,
|
|
|
|
OSD_CAPTURE = 0x00000004,
|
|
|
|
OSD_OVERTYPE = 0x00000008,
|
|
|
|
OSD_SHIFT = 0x00000010,
|
|
|
|
OSD_CTRL = 0x00000020,
|
|
|
|
OSD_CAPS = 0x00000040
|
|
|
|
};
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2012-11-15 14:28:36 +00:00
|
|
|
#define OSD_ALIAS (int32_t (*)(const osdfuncparm_t*))0x1337
|
|
|
|
#define OSD_UNALIASED (int32_t (*)(const osdfuncparm_t*))0xDEAD
|
2008-06-30 00:18:59 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#define OSDCMD_OK 0
|
|
|
|
#define OSDCMD_SHOWHELP 1
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_ParsingScript(void);
|
2008-07-18 23:29:20 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_OSDKey(void);
|
|
|
|
int32_t OSD_GetTextMode(void);
|
|
|
|
void OSD_SetTextMode(int32_t mode);
|
2008-07-18 23:29:20 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_Exec(const char *szScript);
|
2008-07-18 23:29:20 +00:00
|
|
|
|
2013-11-04 22:56:08 +00:00
|
|
|
// Get shade and pal index from the OSD format buffer.
|
|
|
|
void OSD_GetShadePal(const char *ch, int32_t *shadeptr, int32_t *palptr);
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_GetCols(void);
|
2010-05-18 05:14:17 +00:00
|
|
|
int32_t OSD_IsMoving(void);
|
2011-06-04 00:06:08 +00:00
|
|
|
int32_t OSD_GetRowsCur(void);
|
2008-08-17 11:07:28 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
// initializes things
|
|
|
|
void OSD_Init(void);
|
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
// cleans things up. these comments are retarded.
|
|
|
|
void OSD_Cleanup(void);
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
// sets the file to echo output to
|
2012-07-01 22:11:33 +00:00
|
|
|
void OSD_SetLogFile(const char *fn);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// sets the functions the OSD will call to interrogate the environment
|
|
|
|
void OSD_SetFunctions(
|
2009-01-09 09:29:17 +00:00
|
|
|
void (*drawchar)(int32_t,int32_t,char,int32_t,int32_t),
|
2012-12-25 16:13:50 +00:00
|
|
|
void (*drawstr)(int32_t,int32_t,const char*,int32_t,int32_t,int32_t),
|
2009-01-09 09:29:17 +00:00
|
|
|
void (*drawcursor)(int32_t,int32_t,int32_t,int32_t),
|
|
|
|
int32_t (*colwidth)(int32_t),
|
|
|
|
int32_t (*rowheight)(int32_t),
|
|
|
|
void (*clearbg)(int32_t,int32_t),
|
|
|
|
int32_t (*gettime)(void),
|
|
|
|
void (*onshow)(int32_t)
|
2006-04-13 20:47:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// sets the parameters for presenting the text
|
|
|
|
void OSD_SetParameters(
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t promptshade, int32_t promptpal,
|
|
|
|
int32_t editshade, int32_t editpal,
|
|
|
|
int32_t textshade, int32_t textpal
|
2006-04-13 20:47:06 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// sets the scancode for the key which activates the onscreen display
|
2009-01-09 09:29:17 +00:00
|
|
|
void OSD_CaptureKey(int32_t sc);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// handles keyboard input when capturing input. returns 0 if key was handled
|
|
|
|
// or the scancode if it should be handled by the game.
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_HandleScanCode(int32_t sc, int32_t press);
|
|
|
|
int32_t OSD_HandleChar(char ch);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// handles the readjustment when screen resolution changes
|
2009-01-09 09:29:17 +00:00
|
|
|
void OSD_ResizeDisplay(int32_t w,int32_t h);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-12-11 03:32:43 +00:00
|
|
|
// captures and frees osd input
|
2009-01-09 09:29:17 +00:00
|
|
|
void OSD_CaptureInput(int32_t cap);
|
2006-12-11 03:32:43 +00:00
|
|
|
|
2006-12-11 04:38:10 +00:00
|
|
|
// sets the console version string
|
2010-05-02 23:27:30 +00:00
|
|
|
void OSD_SetVersion(const char *version, int32_t shade, int32_t pal);
|
2006-12-11 04:38:10 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
// shows or hides the onscreen display
|
2009-01-09 09:29:17 +00:00
|
|
|
void OSD_ShowDisplay(int32_t onf);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// draw the osd to the screen
|
|
|
|
void OSD_Draw(void);
|
|
|
|
|
|
|
|
// just like printf
|
2011-01-03 22:04:20 +00:00
|
|
|
void OSD_Printf(const char *fmt, ...) ATTRIBUTE((format(printf,1,2)));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-07-24 14:01:44 +00:00
|
|
|
// just like puts
|
|
|
|
void OSD_Puts(const char *str);
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
// executes buffered commands
|
|
|
|
void OSD_DispatchQueued(void);
|
|
|
|
|
|
|
|
// executes a string
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_Dispatch(const char *cmd);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// registers a function
|
|
|
|
// name = name of the function
|
|
|
|
// help = a short help string
|
|
|
|
// func = the entry point to the function
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_RegisterFunction(const char *name, const char *help, int32_t (*func)(const osdfuncparm_t*));
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-04-29 06:20:07 +00:00
|
|
|
int32_t osdcmd_cvar_set(const osdfuncparm_t *parm);
|
|
|
|
int32_t OSD_RegisterCvar(const cvar_t *cvar);
|
2013-12-24 09:44:24 +00:00
|
|
|
void OSD_WriteAliases(FILE *fp);
|
2009-04-30 21:09:44 +00:00
|
|
|
void OSD_WriteCvars(FILE *fp);
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2014-11-06 23:43:49 +00:00
|
|
|
static inline void OSD_SetHistory(int32_t histIdx, const char *src)
|
|
|
|
{
|
|
|
|
osd->history.buf[histIdx] = Xmalloc(OSDEDITLENGTH);
|
|
|
|
Bstrncpyz(osd->history.buf[histIdx], src, OSDEDITLENGTH);
|
|
|
|
}
|
|
|
|
|
2008-07-18 09:50:44 +00:00
|
|
|
// these correspond to the Duke palettes, so they shouldn't really be here
|
|
|
|
// ...but I don't care
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
#define OSDTEXT_BLUE "^00"
|
|
|
|
#define OSDTEXT_GOLD "^07"
|
|
|
|
#define OSDTEXT_DARKRED "^10"
|
|
|
|
#define OSDTEXT_GREEN "^11"
|
|
|
|
#define OSDTEXT_GRAY "^12"
|
|
|
|
#define OSDTEXT_DARKGRAY "^13"
|
2008-07-18 09:50:44 +00:00
|
|
|
#define OSDTEXT_DARKGREEN "^14"
|
2010-05-02 23:27:30 +00:00
|
|
|
#define OSDTEXT_BROWN "^15"
|
|
|
|
#define OSDTEXT_DARKBLUE "^16"
|
|
|
|
#define OSDTEXT_RED "^21"
|
|
|
|
#define OSDTEXT_YELLOW "^23"
|
2008-08-06 11:50:34 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
#define OSDTEXT_BRIGHT "^S0"
|
2008-07-18 13:18:12 +00:00
|
|
|
|
2008-07-27 01:22:17 +00:00
|
|
|
#define OSD_ERROR OSDTEXT_DARKRED OSDTEXT_BRIGHT
|
2010-06-25 23:01:54 +00:00
|
|
|
|
|
|
|
|
2013-05-15 02:16:19 +00:00
|
|
|
extern int32_t osdcmd_restartvid(const osdfuncparm_t *parm);
|
|
|
|
|
2012-11-05 02:49:08 +00:00
|
|
|
#ifdef EXTERNC
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
#endif // __osd_h__
|
|
|
|
|