2006-04-13 20:47:06 +00:00
|
|
|
// On-screen Display (ie. console)
|
|
|
|
// for the Build Engine
|
|
|
|
// by Jonathon Fowler (jonof@edgenetwk.com)
|
|
|
|
|
|
|
|
#include "build.h"
|
|
|
|
#include "osd.h"
|
|
|
|
#include "compat.h"
|
|
|
|
#include "baselayer.h"
|
2008-06-30 07:30:48 +00:00
|
|
|
#include "cache1d.h"
|
2008-07-20 05:31:23 +00:00
|
|
|
#include "pragmas.h"
|
2010-05-02 23:27:30 +00:00
|
|
|
#include "scancodes.h"
|
2010-05-09 22:12:29 +00:00
|
|
|
#include "crc32.h"
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-06-30 00:18:59 +00:00
|
|
|
symbol_t *symbols = NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
static symbol_t *addnewsymbol(const char *name);
|
|
|
|
static symbol_t *findsymbol(const char *name, symbol_t *startingat);
|
|
|
|
static symbol_t *findexactsymbol(const char *name);
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
// static int32_t _validate_osdlines(void *);
|
|
|
|
|
|
|
|
static int32_t _internal_osdfunc_listsymbols(const osdfuncparm_t *);
|
|
|
|
static int32_t _internal_osdfunc_help(const osdfuncparm_t *);
|
|
|
|
static int32_t _internal_osdfunc_alias(const osdfuncparm_t *);
|
|
|
|
// static int32_t _internal_osdfunc_dumpbuildinfo(const osdfuncparm_t *);
|
|
|
|
// static int32_t _internal_osdfunc_setrendermode(const osdfuncparm_t *);
|
|
|
|
|
|
|
|
static int32_t white=-1; // colour of white (used by default display routines)
|
|
|
|
static void _internal_drawosdchar(int32_t, int32_t, char, int32_t, int32_t);
|
|
|
|
static void _internal_drawosdstr(int32_t, int32_t, char*, int32_t, int32_t, int32_t);
|
|
|
|
static void _internal_drawosdcursor(int32_t,int32_t,int32_t,int32_t);
|
|
|
|
static int32_t _internal_getcolumnwidth(int32_t);
|
|
|
|
static int32_t _internal_getrowheight(int32_t);
|
|
|
|
static void _internal_clearbackground(int32_t,int32_t);
|
|
|
|
static int32_t _internal_gettime(void);
|
|
|
|
static void _internal_onshowosd(int32_t);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
static uint32_t osdflags = 0;
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
// history display
|
|
|
|
static char osdtext[TEXTSIZE];
|
2008-07-18 09:50:44 +00:00
|
|
|
static char osdfmt[TEXTSIZE];
|
2010-05-02 23:27:30 +00:00
|
|
|
static char osdver[32];
|
|
|
|
static int32_t osdverlen;
|
|
|
|
static int32_t osdvershade;
|
|
|
|
static int32_t osdverpal;
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdpos=0; // position next character will be written at
|
|
|
|
static int32_t osdlines=1; // # lines of text in the buffer
|
|
|
|
static int32_t osdrows=20; // # lines of the buffer that are visible
|
|
|
|
static int32_t osdrowscur=-1;
|
|
|
|
static int32_t osdscroll=0;
|
|
|
|
static int32_t osdcols=60; // width of onscreen display in text columns
|
|
|
|
static int32_t osdmaxrows=20; // maximum number of lines which can fit on the screen
|
|
|
|
static int32_t osdmaxlines=TEXTSIZE/60; // maximum lines which can fit in the buffer
|
|
|
|
static int32_t osdhead=0; // topmost visible line number
|
2008-08-23 15:37:30 +00:00
|
|
|
static BFILE *osdlog=NULL; // log filehandle
|
2010-05-02 23:27:30 +00:00
|
|
|
static int32_t osdkey=sc_Tilde;
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t keytime=0;
|
|
|
|
static int32_t osdscrtime = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// command prompt editing
|
2008-07-07 12:17:27 +00:00
|
|
|
#define EDITLENGTH 511
|
2008-08-23 15:37:30 +00:00
|
|
|
static char osdeditbuf[EDITLENGTH+1]; // editing buffer
|
|
|
|
static char osdedittmp[EDITLENGTH+1]; // editing buffer temporary workspace
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdeditlen=0; // length of characters in edit buffer
|
|
|
|
static int32_t osdeditcursor=0; // position of cursor in edit buffer
|
|
|
|
static int32_t osdeditwinstart=0;
|
|
|
|
static int32_t osdeditwinend=60-1-3;
|
2006-04-13 20:47:06 +00:00
|
|
|
#define editlinewidth (osdcols-1-3)
|
|
|
|
|
|
|
|
// command processing
|
2008-07-07 06:44:41 +00:00
|
|
|
#define HISTORYDEPTH 32
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdhistorypos=-1; // position we are at in the history buffer
|
2008-08-23 15:37:30 +00:00
|
|
|
static char osdhistorybuf[HISTORYDEPTH][EDITLENGTH+1]; // history strings
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdhistorysize=0; // number of entries in history
|
|
|
|
static int32_t osdhistorytotal=0; // number of total history entries
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
// execution buffer
|
|
|
|
// the execution buffer works from the command history
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdexeccount=0; // number of lines from the head of the history buffer to execute
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-01-04 01:04:35 +00:00
|
|
|
// maximal log line count
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t logcutoff=120000;
|
|
|
|
int32_t OSD_errors=0;
|
|
|
|
static int32_t linecnt;
|
|
|
|
static int32_t osdexecscript=0;
|
2008-07-23 03:56:50 +00:00
|
|
|
#ifdef _WIN32
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdtextmode=0;
|
2008-07-23 03:56:50 +00:00
|
|
|
#else
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdtextmode=1;
|
2008-07-23 03:56:50 +00:00
|
|
|
#endif
|
2006-04-13 20:47:06 +00:00
|
|
|
// presentation parameters
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdpromptshade=0;
|
|
|
|
static int32_t osdpromptpal=0;
|
|
|
|
static int32_t osdeditshade=0;
|
|
|
|
static int32_t osdeditpal=0;
|
|
|
|
static int32_t osdtextshade=0;
|
|
|
|
static int32_t osdtextpal=0;
|
|
|
|
/* static int32_t osdcursorshade=0;
|
|
|
|
static int32_t osdcursorpal=0; */
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-08-25 02:12:02 +00:00
|
|
|
#define MAXSYMBOLS 256
|
|
|
|
|
|
|
|
static symbol_t *osdsymbptrs[MAXSYMBOLS];
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdnumsymbols = 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
static hashtable_t h_osd = { MAXSYMBOLS<<1, NULL };
|
2008-08-25 02:12:02 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
// application callbacks
|
2009-01-09 09:29:17 +00:00
|
|
|
static void (*drawosdchar)(int32_t, int32_t, char, int32_t, int32_t) = _internal_drawosdchar;
|
|
|
|
static void (*drawosdstr)(int32_t, int32_t, char*, int32_t, int32_t, int32_t) = _internal_drawosdstr;
|
|
|
|
static void (*drawosdcursor)(int32_t, int32_t, int32_t, int32_t) = _internal_drawosdcursor;
|
|
|
|
static int32_t (*getcolumnwidth)(int32_t) = _internal_getcolumnwidth;
|
|
|
|
static int32_t (*getrowheight)(int32_t) = _internal_getrowheight;
|
|
|
|
static void (*clearbackground)(int32_t,int32_t) = _internal_clearbackground;
|
|
|
|
static int32_t (*gettime)(void) = _internal_gettime;
|
|
|
|
static void (*onshowosd)(int32_t) = _internal_onshowosd;
|
|
|
|
|
|
|
|
static void (*_drawosdchar)(int32_t, int32_t, char, int32_t, int32_t) = _internal_drawosdchar;
|
|
|
|
static void (*_drawosdstr)(int32_t, int32_t, char*, int32_t, int32_t, int32_t) = _internal_drawosdstr;
|
|
|
|
static void (*_drawosdcursor)(int32_t, int32_t, int32_t, int32_t) = _internal_drawosdcursor;
|
|
|
|
static int32_t (*_getcolumnwidth)(int32_t) = _internal_getcolumnwidth;
|
|
|
|
static int32_t (*_getrowheight)(int32_t) = _internal_getrowheight;
|
2008-07-20 05:31:23 +00:00
|
|
|
|
2009-04-29 19:43:51 +00:00
|
|
|
static cvar_t *cvars = NULL;
|
2009-04-29 06:20:07 +00:00
|
|
|
static uint32_t osdnumcvars = 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
static hashtable_t h_cvars = { MAXSYMBOLS<<1, NULL };
|
2008-08-03 11:45:15 +00:00
|
|
|
|
2009-04-29 06:20:07 +00:00
|
|
|
int32_t OSD_RegisterCvar(const cvar_t *cvar)
|
|
|
|
{
|
|
|
|
const char *cp;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if ((osdflags & OSD_INITIALIZED) == 0)
|
|
|
|
OSD_Init();
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (!cvar->name || !cvar->name[0])
|
2009-04-29 06:20:07 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_Printf("OSD_RegisterCvar(): can't register cvar with null name\n");
|
2009-04-29 06:20:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
|
|
|
|
if (!cvar->var)
|
2009-04-29 06:20:07 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_Printf("OSD_RegisterCvar(): can't register null cvar\n");
|
2009-04-29 06:20:07 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for illegal characters in name
|
|
|
|
for (cp = cvar->name; *cp; cp++)
|
|
|
|
{
|
|
|
|
if ((cp == cvar->name) && (*cp >= '0') && (*cp <= '9'))
|
|
|
|
{
|
|
|
|
OSD_Printf("OSD_RegisterCvar(): first character of cvar name \"%s\" must not be a numeral\n", cvar->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((*cp < '0') ||
|
2009-04-30 01:07:08 +00:00
|
|
|
(*cp > '9' && *cp < 'A') ||
|
|
|
|
(*cp > 'Z' && *cp < 'a' && *cp != '_') ||
|
|
|
|
(*cp > 'z'))
|
2009-04-29 06:20:07 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("OSD_RegisterCvar(): illegal character in cvar name \"%s\"\n", cvar->name);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cvars = Brealloc(cvars, (osdnumcvars + 1) * sizeof(cvar_t));
|
2010-05-02 23:27:30 +00:00
|
|
|
hash_add(&h_cvars, cvar->name, osdnumcvars);
|
2009-04-29 06:20:07 +00:00
|
|
|
Bmemcpy(&cvars[osdnumcvars++], cvar, sizeof(cvar_t));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
// color code format is as follows:
|
|
|
|
// ^## sets a color, where ## is the palette number
|
|
|
|
// ^S# sets a shade, range is 0-7 equiv to shades 0-14
|
|
|
|
// ^O resets formatting to defaults
|
|
|
|
|
|
|
|
const char * OSD_StripColors(char *out, const char *in)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
const char *ptr = out;
|
2008-06-30 07:30:48 +00:00
|
|
|
|
2008-08-24 05:39:28 +00:00
|
|
|
do
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2008-08-03 11:45:15 +00:00
|
|
|
if (*in == '^' && isdigit(*(in+1)))
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2008-08-03 11:45:15 +00:00
|
|
|
in += 2;
|
|
|
|
if (isdigit(*in))
|
|
|
|
in++;
|
2008-06-30 07:30:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-08-03 11:45:15 +00:00
|
|
|
if (*in == '^' && (Btoupper(*(in+1)) == 'S') && isdigit(*(in+2)))
|
2008-07-19 07:39:51 +00:00
|
|
|
{
|
2008-08-03 11:45:15 +00:00
|
|
|
in += 3;
|
2008-07-19 07:39:51 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-08-03 11:45:15 +00:00
|
|
|
if (*in == '^' && (Btoupper(*(in+1)) == 'O'))
|
2008-07-19 00:50:20 +00:00
|
|
|
{
|
2008-08-03 11:45:15 +00:00
|
|
|
in += 2;
|
2008-07-19 00:50:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
*(out++) = *in;
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
while (*(++in));
|
2008-08-24 05:39:28 +00:00
|
|
|
|
2008-08-03 11:45:15 +00:00
|
|
|
*out = '\0';
|
2010-05-02 23:27:30 +00:00
|
|
|
return (ptr);
|
2008-06-30 07:30:48 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_Exec(const char *szScript)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
|
|
|
FILE* fp = fopenfrompath(szScript, "r");
|
|
|
|
|
|
|
|
if (fp != NULL)
|
|
|
|
{
|
|
|
|
char line[255];
|
|
|
|
|
|
|
|
OSD_Printf("Executing \"%s\"\n", szScript);
|
|
|
|
osdexecscript++;
|
2010-05-02 23:27:30 +00:00
|
|
|
while (fgets(line, sizeof(line)-1, fp) != NULL)
|
2008-06-30 07:30:48 +00:00
|
|
|
OSD_Dispatch(strtok(line,"\r\n"));
|
|
|
|
osdexecscript--;
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_ParsingScript(void)
|
2008-07-23 03:56:50 +00:00
|
|
|
{
|
|
|
|
return osdexecscript;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_OSDKey(void)
|
2008-07-23 03:56:50 +00:00
|
|
|
{
|
|
|
|
return osdkey;
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
char * OSD_GetTextPtr(void)
|
2008-07-23 03:56:50 +00:00
|
|
|
{
|
|
|
|
return (&osdtext[0]);
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
char * OSD_GetFmtPtr(void)
|
2008-07-23 03:56:50 +00:00
|
|
|
{
|
|
|
|
return (&osdfmt[0]);
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
char * OSD_GetFmt(char *ptr)
|
2008-07-23 03:56:50 +00:00
|
|
|
{
|
|
|
|
return (ptr - &osdtext[0] + &osdfmt[0]);
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_GetCols(void)
|
2008-08-17 11:07:28 +00:00
|
|
|
{
|
|
|
|
return osdcols;
|
|
|
|
}
|
|
|
|
|
2010-05-18 05:14:17 +00:00
|
|
|
int32_t OSD_IsMoving(void)
|
|
|
|
{
|
|
|
|
return (osdrowscur!=-1 && osdrowscur!=osdrows);
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_GetTextMode(void)
|
2008-07-23 03:56:50 +00:00
|
|
|
{
|
|
|
|
return osdtextmode;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
void OSD_SetTextMode(int32_t mode)
|
2008-07-23 03:56:50 +00:00
|
|
|
{
|
|
|
|
osdtextmode = (mode != 0);
|
|
|
|
if (osdtextmode)
|
|
|
|
{
|
|
|
|
if (drawosdchar != _internal_drawosdchar)
|
|
|
|
{
|
|
|
|
swaplong(&_drawosdchar,&drawosdchar);
|
|
|
|
swaplong(&_drawosdstr,&drawosdstr);
|
|
|
|
swaplong(&_drawosdcursor,&drawosdcursor);
|
|
|
|
swaplong(&_getcolumnwidth,&getcolumnwidth);
|
|
|
|
swaplong(&_getrowheight,&getrowheight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (drawosdchar == _internal_drawosdchar)
|
|
|
|
{
|
|
|
|
swaplong(&_drawosdchar,&drawosdchar);
|
|
|
|
swaplong(&_drawosdstr,&drawosdstr);
|
|
|
|
swaplong(&_drawosdcursor,&drawosdcursor);
|
|
|
|
swaplong(&_getcolumnwidth,&getcolumnwidth);
|
|
|
|
swaplong(&_getrowheight,&getrowheight);
|
|
|
|
}
|
|
|
|
if (qsetmode == 200)
|
|
|
|
OSD_ResizeDisplay(xdim, ydim);
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_osdfunc_exec(const osdfuncparm_t *parm)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
|
|
|
char fn[BMAX_PATH];
|
|
|
|
|
|
|
|
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
|
|
|
|
Bstrcpy(fn,parm->parms[0]);
|
|
|
|
|
|
|
|
if (OSD_Exec(fn))
|
|
|
|
{
|
2008-07-27 01:22:17 +00:00
|
|
|
OSD_Printf(OSD_ERROR "exec: file \"%s\" not found.\n", fn);
|
2008-06-30 07:30:48 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-09 22:12:29 +00:00
|
|
|
static int32_t _internal_osdfunc_echo(const osdfuncparm_t *parm)
|
|
|
|
{
|
|
|
|
int32_t i;
|
|
|
|
for (i = 0; i < parm->numparms; i++)
|
|
|
|
{
|
|
|
|
if (i > 0) OSD_Printf(" ");
|
|
|
|
OSD_Printf("%s", parm->parms[i]);
|
|
|
|
}
|
|
|
|
OSD_Printf("\n");
|
|
|
|
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int32_t _internal_osdfunc_fileinfo(const osdfuncparm_t *parm)
|
|
|
|
{
|
|
|
|
uint32_t crc, length;
|
|
|
|
int32_t i,j;
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
|
|
|
|
|
|
|
|
if ((i = kopen4load((char *)parm->parms[0],0)) < 0)
|
|
|
|
{
|
|
|
|
OSD_Printf("fileinfo: File \"%s\" not found.\n", parm->parms[0]);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = kfilelength(i);
|
|
|
|
|
|
|
|
crc32init(&crc);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
j = kread(i,buf,256);
|
|
|
|
crc32block(&crc,(uint8_t *)buf,j);
|
|
|
|
}
|
|
|
|
while (j == 256);
|
|
|
|
crc32finish(&crc);
|
|
|
|
|
|
|
|
kclose(i);
|
|
|
|
|
|
|
|
OSD_Printf("fileinfo: %s\n"
|
|
|
|
" File size: %d\n"
|
|
|
|
" CRC-32: %08X\n",
|
|
|
|
parm->parms[0], length, crc);
|
|
|
|
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void _internal_drawosdchar(int32_t x, int32_t y, char ch, int32_t shade, int32_t pal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char st[2] = { 0,0 };
|
|
|
|
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(shade);
|
|
|
|
UNREFERENCED_PARAMETER(pal);
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
st[0] = ch;
|
|
|
|
|
|
|
|
printext256(4+(x<<3),4+(y<<3), white, -1, st, 0);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void _internal_drawosdstr(int32_t x, int32_t y, char *ch, int32_t len, int32_t shade, int32_t pal)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char st[1024];
|
|
|
|
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(shade);
|
|
|
|
UNREFERENCED_PARAMETER(pal);
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (len>1023) len=1023;
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(st,ch,len);
|
2006-04-24 19:04:22 +00:00
|
|
|
st[len]=0;
|
|
|
|
|
|
|
|
printext256(4+(x<<3),4+(y<<3), white, -1, st, 0);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void _internal_drawosdcursor(int32_t x, int32_t y, int32_t type, int32_t lastkeypress)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char st[2] = { '_',0 };
|
|
|
|
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(lastkeypress);
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (type) st[0] = '#';
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (white > -1)
|
|
|
|
{
|
|
|
|
printext256(4+(x<<3),4+(y<<3)+2, white, -1, st, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
int32_t i, j, k;
|
2006-04-24 19:04:22 +00:00
|
|
|
// find the palette index closest to white
|
|
|
|
k=0;
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=0; i<256; i++)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
j = ((int32_t)curpalette[i].r)+((int32_t)curpalette[i].g)+((int32_t)curpalette[i].b);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (j > k) { k = j; white = i; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_getcolumnwidth(int32_t w)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
return w/8 - 1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_getrowheight(int32_t w)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
return w/8;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void _internal_clearbackground(int32_t cols, int32_t rows)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(cols);
|
|
|
|
UNREFERENCED_PARAMETER(rows);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_gettime(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void _internal_onshowosd(int32_t a)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(a);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_osdfunc_alias(const osdfuncparm_t *parm)
|
2008-06-29 22:37:30 +00:00
|
|
|
{
|
|
|
|
symbol_t *i;
|
|
|
|
|
|
|
|
if (parm->numparms < 1)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t j = 0;
|
2008-06-29 22:37:30 +00:00
|
|
|
OSD_Printf("Alias listing:\n");
|
|
|
|
for (i=symbols; i!=NULL; i=i->next)
|
2010-05-02 23:27:30 +00:00
|
|
|
if (i->func == OSD_ALIAS)
|
2008-07-02 22:45:04 +00:00
|
|
|
{
|
|
|
|
j++;
|
2008-06-30 07:30:48 +00:00
|
|
|
OSD_Printf(" %s \"%s\"\n", i->name, i->help);
|
2008-07-02 22:45:04 +00:00
|
|
|
}
|
|
|
|
if (j == 0)
|
|
|
|
OSD_Printf("No aliases found.\n");
|
2008-06-29 22:37:30 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2008-06-30 00:18:59 +00:00
|
|
|
for (i=symbols; i!=NULL; i=i->next)
|
2008-06-29 22:37:30 +00:00
|
|
|
{
|
2008-06-30 00:32:05 +00:00
|
|
|
if (!Bstrcasecmp(parm->parms[0],i->name))
|
2008-06-30 00:18:59 +00:00
|
|
|
{
|
2008-06-30 00:32:05 +00:00
|
|
|
if (parm->numparms < 2)
|
2008-06-30 00:18:59 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (i->func == OSD_ALIAS)
|
2008-06-30 00:18:59 +00:00
|
|
|
OSD_Printf("alias %s \"%s\"\n", i->name, i->help);
|
|
|
|
else OSD_Printf("%s is a function, not an alias\n",i->name);
|
2008-06-30 00:32:05 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
if (i->func != OSD_ALIAS && i->func != OSD_UNALIASED)
|
2008-06-30 00:32:05 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("Cannot override function \"%s\" with alias\n",i->name);
|
|
|
|
return OSDCMD_OK;
|
2008-06-30 00:18:59 +00:00
|
|
|
}
|
|
|
|
}
|
2008-06-29 22:37:30 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_RegisterFunction(Bstrdup(parm->parms[0]),Bstrdup(parm->parms[1]),OSD_ALIAS);
|
2008-06-30 07:30:48 +00:00
|
|
|
if (!osdexecscript)
|
|
|
|
OSD_Printf("%s\n",parm->raw);
|
2008-06-29 22:37:30 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_osdfunc_unalias(const osdfuncparm_t *parm)
|
2008-06-30 01:03:51 +00:00
|
|
|
{
|
|
|
|
symbol_t *i;
|
|
|
|
|
|
|
|
if (parm->numparms < 1)
|
|
|
|
return OSDCMD_SHOWHELP;
|
|
|
|
|
|
|
|
for (i=symbols; i!=NULL; i=i->next)
|
|
|
|
{
|
|
|
|
if (!Bstrcasecmp(parm->parms[0],i->name))
|
|
|
|
{
|
|
|
|
if (parm->numparms < 2)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (i->func == OSD_ALIAS)
|
2008-06-30 01:03:51 +00:00
|
|
|
{
|
2008-06-30 07:30:48 +00:00
|
|
|
OSD_Printf("Removed alias %s (\"%s\")\n", i->name, i->help);
|
2010-05-02 23:27:30 +00:00
|
|
|
i->func = OSD_UNALIASED;
|
2008-06-30 01:03:51 +00:00
|
|
|
}
|
|
|
|
else OSD_Printf("Invalid alias %s\n",i->name);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
OSD_Printf("Invalid alias %s\n",parm->parms[0]);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_osdfunc_listsymbols(const osdfuncparm_t *parm)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
symbol_t *i;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t maxwidth = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(parm);
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
for (i=symbols; i!=NULL; i=i->next)
|
2010-05-02 23:27:30 +00:00
|
|
|
if (i->func != OSD_UNALIASED)
|
2008-06-30 07:30:48 +00:00
|
|
|
maxwidth = max((unsigned)maxwidth,Bstrlen(i->name));
|
|
|
|
|
|
|
|
if (maxwidth > 0)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t x = 0, count = 0;
|
2008-06-30 07:30:48 +00:00
|
|
|
maxwidth += 3;
|
2008-08-11 23:22:29 +00:00
|
|
|
OSD_Printf(OSDTEXT_RED "Symbol listing:\n");
|
2008-06-30 07:30:48 +00:00
|
|
|
for (i=symbols; i!=NULL; i=i->next)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (i->func != OSD_UNALIASED)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("%-*s",maxwidth,i->name);
|
|
|
|
x += maxwidth;
|
2008-07-30 05:41:03 +00:00
|
|
|
count++;
|
2008-06-30 07:30:48 +00:00
|
|
|
}
|
|
|
|
if (x > osdcols - maxwidth)
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
OSD_Printf("\n");
|
|
|
|
}
|
|
|
|
}
|
2008-07-30 05:41:03 +00:00
|
|
|
if (x) OSD_Printf("\n");
|
|
|
|
OSD_Printf(OSDTEXT_RED "Found %d symbols\n",count);
|
2008-06-30 07:30:48 +00:00
|
|
|
}
|
2006-04-24 19:04:22 +00:00
|
|
|
return OSDCMD_OK;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_osdfunc_help(const osdfuncparm_t *parm)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
symbol_t *symb;
|
|
|
|
|
|
|
|
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
|
|
|
|
symb = findexactsymbol(parm->parms[0]);
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!symb)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
OSD_Printf("Help Error: \"%s\" is not a defined variable or function\n", parm->parms[0]);
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
OSD_Printf("%s\n", symb->help);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OSDCMD_OK;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_osdfunc_clear(const osdfuncparm_t *parm)
|
2007-01-04 07:15:17 +00:00
|
|
|
{
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(parm);
|
2007-01-04 07:15:17 +00:00
|
|
|
Bmemset(osdtext,0,sizeof(osdtext));
|
2008-07-18 13:18:12 +00:00
|
|
|
Bmemset(osdfmt,osdtextpal+(osdtextshade<<5),sizeof(osdfmt));
|
2007-01-04 07:15:17 +00:00
|
|
|
osdlines = 1;
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t _internal_osdfunc_history(const osdfuncparm_t *parm)
|
2008-07-07 12:17:27 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i, j = 0;
|
2008-07-07 12:17:27 +00:00
|
|
|
UNREFERENCED_PARAMETER(parm);
|
2008-08-18 07:20:36 +00:00
|
|
|
OSD_Printf(OSDTEXT_RED "Command history:\n");
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=HISTORYDEPTH-1; i>=0; i--)
|
2008-07-07 12:17:27 +00:00
|
|
|
if (osdhistorybuf[i][0])
|
2008-07-07 12:35:21 +00:00
|
|
|
OSD_Printf("%4d \"%s\"\n",osdhistorytotal-osdhistorysize+(++j),osdhistorybuf[i]);
|
2008-07-07 12:17:27 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_Cleanup() -- Cleans up the on-screen display
|
|
|
|
//
|
|
|
|
void OSD_Cleanup(void)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
symbol_t *s;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
hash_free(&h_osd);
|
|
|
|
hash_free(&h_cvars);
|
2008-08-25 02:12:02 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (; symbols; symbols=s)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
s=symbols->next;
|
|
|
|
Bfree(symbols);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (osdlog) Bfclose(osdlog);
|
|
|
|
osdlog = NULL;
|
2006-04-24 18:52:29 +00:00
|
|
|
|
2009-04-29 06:20:07 +00:00
|
|
|
if (cvars)
|
|
|
|
{
|
|
|
|
Bfree(cvars);
|
|
|
|
cvars = NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
osdflags &= ~OSD_INITIALIZED;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-30 01:07:08 +00:00
|
|
|
static int32_t osdcmd_cvar_set_osd(const osdfuncparm_t *parm)
|
|
|
|
{
|
|
|
|
int32_t r = osdcmd_cvar_set(parm);
|
|
|
|
|
|
|
|
if (r == OSDCMD_OK)
|
|
|
|
{
|
|
|
|
if (!Bstrcasecmp(parm->name, "osdrows"))
|
|
|
|
{
|
|
|
|
if (osdrows > osdmaxrows) osdrows = osdmaxrows;
|
|
|
|
if (osdrowscur!=-1)osdrowscur = osdrows;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
else if (!Bstrcasecmp(parm->name, "osdtextmode"))
|
|
|
|
{
|
|
|
|
OSD_SetTextMode(osdtextmode);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
2008-02-24 00:46:57 +00:00
|
|
|
// OSD_Init() -- Initializes the on-screen display
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
|
|
|
void OSD_Init(void)
|
|
|
|
{
|
2009-04-30 01:07:08 +00:00
|
|
|
uint32_t i;
|
|
|
|
cvar_t cvars_osd[] =
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
{ "osdeditpal","osdeditpal: sets the palette of the OSD input text",(void *)&osdeditpal, CVAR_INT, 0, MAXPALOOKUPS-1 },
|
|
|
|
{ "osdpromptpal","osdpromptpal: sets the palette of the OSD prompt",(void *)&osdpromptpal, CVAR_INT, 0, MAXPALOOKUPS-1 },
|
|
|
|
{ "osdtextpal","osdtextpal: sets the palette of the OSD text",(void *)&osdtextpal, CVAR_INT, 0, MAXPALOOKUPS-1 },
|
|
|
|
{ "osdeditshade","osdeditshade: sets the shade of the OSD input text",(void *)&osdeditshade, CVAR_INT, 0, 7 },
|
|
|
|
{ "osdtextshade","osdtextshade: sets the shade of the OSD text",(void *)&osdtextshade, CVAR_INT, 0, 7 },
|
2010-05-09 22:12:29 +00:00
|
|
|
{ "osdpromptshade","osdpromptshade: sets the shade of the OSD prompt",(void *)&osdpromptshade, CVAR_INT, INT8_MIN, INT8_MAX },
|
2010-05-02 23:27:30 +00:00
|
|
|
{ "osdrows","osdrows: sets the number of visible lines of the OSD",(void *)&osdrows, CVAR_INT|CVAR_FUNCPTR, 0, MAXPALOOKUPS-1 },
|
|
|
|
{ "osdtextmode","osdtextmode: set OSD text mode (0:graphical, 1:fast)",(void *)&osdtextmode, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 },
|
|
|
|
{ "logcutoff","logcutoff: sets the maximal line count of the log file",(void *)&logcutoff, CVAR_INT, 0, 262144 },
|
2009-04-30 01:07:08 +00:00
|
|
|
};
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
Bmemset(osdtext, asc_Space, TEXTSIZE);
|
2008-07-18 13:18:12 +00:00
|
|
|
Bmemset(osdfmt, osdtextpal+(osdtextshade<<5), TEXTSIZE);
|
2008-08-25 02:12:02 +00:00
|
|
|
Bmemset(osdsymbptrs, 0, sizeof(osdsymbptrs));
|
|
|
|
|
2009-04-29 06:20:07 +00:00
|
|
|
osdnumsymbols = osdnumcvars = 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
osdlines = 1;
|
|
|
|
osdflags |= OSD_INITIALIZED;
|
2008-08-25 02:12:02 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
hash_init(&h_osd);
|
|
|
|
hash_init(&h_cvars);
|
2008-08-25 02:12:02 +00:00
|
|
|
|
2009-04-30 01:07:08 +00:00
|
|
|
for (i=0; i<sizeof(cvars_osd)/sizeof(cvars_osd[0]); i++)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (OSD_RegisterCvar(&cvars_osd[i]))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
OSD_RegisterFunction(cvars_osd[i].name, cvars_osd[i].helpstr,
|
|
|
|
cvars_osd[i].type & CVAR_FUNCPTR ? osdcmd_cvar_set_osd : osdcmd_cvar_set);
|
2009-04-30 01:07:08 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2008-07-09 09:34:12 +00:00
|
|
|
OSD_RegisterFunction("alias","alias: creates an alias for calling multiple commands",_internal_osdfunc_alias);
|
|
|
|
OSD_RegisterFunction("clear","clear: clears the console text buffer",_internal_osdfunc_clear);
|
2010-05-09 22:12:29 +00:00
|
|
|
OSD_RegisterFunction("echo","echo [text]: echoes text to the console", _internal_osdfunc_echo);
|
2008-07-09 09:34:12 +00:00
|
|
|
OSD_RegisterFunction("exec","exec <scriptfile>: executes a script", _internal_osdfunc_exec);
|
2010-05-09 22:12:29 +00:00
|
|
|
OSD_RegisterFunction("fileinfo","fileinfo <file>: gets a file's information", _internal_osdfunc_fileinfo);
|
2008-07-09 09:34:12 +00:00
|
|
|
OSD_RegisterFunction("help","help: displays help for the specified cvar or command; \"listsymbols\" to show all commands",_internal_osdfunc_help);
|
|
|
|
OSD_RegisterFunction("history","history: displays the console command history",_internal_osdfunc_history);
|
2010-05-09 22:12:29 +00:00
|
|
|
OSD_RegisterFunction("listsymbols","listsymbols: lists all registered functions, cvars and aliases",_internal_osdfunc_listsymbols);
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_RegisterFunction("unalias","unalias: removes a command alias",_internal_osdfunc_unalias);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
atexit(OSD_Cleanup);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_SetLogFile() -- Sets the text file where printed text should be echoed
|
|
|
|
//
|
|
|
|
void OSD_SetLogFile(char *fn)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (osdlog) Bfclose(osdlog);
|
|
|
|
osdlog = NULL;
|
|
|
|
if (fn) osdlog = Bfopen(fn,"w");
|
|
|
|
if (osdlog) setvbuf(osdlog, (char*)NULL, _IONBF, 0);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_SetFunctions() -- Sets some callbacks which the OSD uses to understand its world
|
|
|
|
//
|
|
|
|
void OSD_SetFunctions(
|
2009-01-09 09:29:17 +00:00
|
|
|
void (*drawchar)(int32_t,int32_t,char,int32_t,int32_t),
|
|
|
|
void (*drawstr)(int32_t,int32_t,char*,int32_t,int32_t,int32_t),
|
|
|
|
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 (*gtime)(void),
|
|
|
|
void (*showosd)(int32_t)
|
2006-04-24 19:04:22 +00:00
|
|
|
)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
drawosdchar = drawchar;
|
|
|
|
drawosdstr = drawstr;
|
|
|
|
drawosdcursor = drawcursor;
|
|
|
|
getcolumnwidth = colwidth;
|
|
|
|
getrowheight = rowheight;
|
|
|
|
clearbackground = clearbg;
|
|
|
|
gettime = gtime;
|
|
|
|
onshowosd = showosd;
|
|
|
|
|
|
|
|
if (!drawosdchar) drawosdchar = _internal_drawosdchar;
|
|
|
|
if (!drawosdstr) drawosdstr = _internal_drawosdstr;
|
|
|
|
if (!drawosdcursor) drawosdcursor = _internal_drawosdcursor;
|
|
|
|
if (!getcolumnwidth) getcolumnwidth = _internal_getcolumnwidth;
|
|
|
|
if (!getrowheight) getrowheight = _internal_getrowheight;
|
|
|
|
if (!clearbackground) clearbackground = _internal_clearbackground;
|
|
|
|
if (!gettime) gettime = _internal_gettime;
|
|
|
|
if (!onshowosd) onshowosd = _internal_onshowosd;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_SetParameters() -- 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-24 19:04:22 +00:00
|
|
|
)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
osdpromptshade = promptshade;
|
|
|
|
osdpromptpal = promptpal;
|
|
|
|
osdeditshade = editshade;
|
|
|
|
osdeditpal = editpal;
|
|
|
|
osdtextshade = textshade;
|
|
|
|
osdtextpal = textpal;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_CaptureKey() -- 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
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
osdkey = sc;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2008-07-01 10:31:03 +00:00
|
|
|
//
|
|
|
|
// OSD_FindDiffPoint() -- Finds the length of the longest common prefix of 2 strings, stolen from ZDoom
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t OSD_FindDiffPoint(const char *str1, const char *str2)
|
2008-07-01 11:14:18 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2008-07-01 11:14:18 +00:00
|
|
|
|
|
|
|
for (i = 0; Btolower(str1[i]) == Btolower(str2[i]); i++)
|
|
|
|
if (str1[i] == 0 || str2[i] == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2008-07-08 04:52:39 +00:00
|
|
|
static void OSD_HistoryPrev(void)
|
|
|
|
{
|
2008-07-09 09:34:12 +00:00
|
|
|
if (osdhistorypos >= osdhistorysize-1) return;
|
|
|
|
|
|
|
|
osdhistorypos++;
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(osdeditbuf, osdhistorybuf[osdhistorypos], EDITLENGTH+1);
|
2010-05-02 23:27:30 +00:00
|
|
|
|
|
|
|
osdeditcursor = 0;
|
|
|
|
while (osdeditbuf[osdeditcursor]) osdeditcursor++;
|
|
|
|
osdeditlen = osdeditcursor;
|
|
|
|
|
2008-07-09 09:34:12 +00:00
|
|
|
if (osdeditcursor<osdeditwinstart)
|
2008-07-08 04:52:39 +00:00
|
|
|
{
|
2008-07-09 09:34:12 +00:00
|
|
|
osdeditwinend = osdeditcursor;
|
|
|
|
osdeditwinstart = osdeditwinend-editlinewidth;
|
2008-07-08 04:52:39 +00:00
|
|
|
|
2008-07-09 09:34:12 +00:00
|
|
|
if (osdeditwinstart<0)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
|
|
|
osdeditwinend-=osdeditwinstart;
|
|
|
|
osdeditwinstart=0;
|
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
}
|
2008-07-09 09:34:12 +00:00
|
|
|
else if (osdeditcursor>=osdeditwinend)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
|
|
|
osdeditwinstart+=(osdeditcursor-osdeditwinend);
|
|
|
|
osdeditwinend+=(osdeditcursor-osdeditwinend);
|
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void OSD_HistoryNext(void)
|
|
|
|
{
|
2008-07-09 09:34:12 +00:00
|
|
|
if (osdhistorypos < 0) return;
|
|
|
|
|
|
|
|
if (osdhistorypos == 0)
|
2008-07-08 04:52:39 +00:00
|
|
|
{
|
2008-07-09 09:34:12 +00:00
|
|
|
osdeditlen=0;
|
|
|
|
osdeditcursor=0;
|
|
|
|
osdeditwinstart=0;
|
|
|
|
osdeditwinend=editlinewidth;
|
|
|
|
osdhistorypos = -1;
|
|
|
|
return;
|
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
|
2008-07-09 09:34:12 +00:00
|
|
|
osdhistorypos--;
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(osdeditbuf, osdhistorybuf[osdhistorypos], EDITLENGTH+1);
|
2010-05-02 23:27:30 +00:00
|
|
|
|
|
|
|
osdeditcursor = 0;
|
|
|
|
while (osdeditbuf[osdeditcursor]) osdeditcursor++;
|
|
|
|
osdeditlen = osdeditcursor;
|
|
|
|
|
2008-07-09 09:34:12 +00:00
|
|
|
if (osdeditcursor<osdeditwinstart)
|
|
|
|
{
|
|
|
|
osdeditwinend = osdeditcursor;
|
|
|
|
osdeditwinstart = osdeditwinend-editlinewidth;
|
|
|
|
|
|
|
|
if (osdeditwinstart<0)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
|
|
|
osdeditwinend-=osdeditwinstart;
|
|
|
|
osdeditwinstart=0;
|
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
}
|
2008-07-09 09:34:12 +00:00
|
|
|
else if (osdeditcursor>=osdeditwinend)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
|
|
|
osdeditwinstart+=(osdeditcursor-osdeditwinend);
|
|
|
|
osdeditwinend+=(osdeditcursor-osdeditwinend);
|
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
//
|
|
|
|
// OSD_HandleKey() -- Handles keyboard input when capturing input.
|
|
|
|
// Returns 0 if the key was handled internally, or the scancode if it should
|
|
|
|
// be passed on to the game.
|
|
|
|
//
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_HandleChar(char ch)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i,j;
|
2006-04-24 19:04:22 +00:00
|
|
|
symbol_t *tabc = NULL;
|
|
|
|
static symbol_t *lastmatch = NULL;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if ((osdflags & (OSD_INITIALIZED|OSD_CAPTURE)) != (OSD_INITIALIZED|OSD_CAPTURE))
|
|
|
|
return ch;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (ch != 9) // tab
|
|
|
|
lastmatch = NULL;
|
|
|
|
|
|
|
|
switch (ch)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
case 1: // control a. jump to beginning of line
|
2008-07-08 04:52:39 +00:00
|
|
|
osdeditcursor=0;
|
|
|
|
osdeditwinstart=0;
|
|
|
|
osdeditwinend=editlinewidth;
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 2: // control b, move one character left
|
2008-07-08 04:52:39 +00:00
|
|
|
if (osdeditcursor > 0) osdeditcursor--;
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 3: // control c
|
2008-07-21 03:24:06 +00:00
|
|
|
osdeditbuf[osdeditlen] = 0;
|
2008-07-08 04:52:39 +00:00
|
|
|
OSD_Printf("%s\n",osdeditbuf);
|
|
|
|
osdeditlen=0;
|
|
|
|
osdeditcursor=0;
|
|
|
|
osdeditwinstart=0;
|
|
|
|
osdeditwinend=editlinewidth;
|
|
|
|
osdeditbuf[0] = 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 5: // control e, jump to end of line
|
2008-07-08 04:52:39 +00:00
|
|
|
osdeditcursor = osdeditlen;
|
|
|
|
osdeditwinend = osdeditcursor;
|
|
|
|
osdeditwinstart = osdeditwinend-editlinewidth;
|
|
|
|
if (osdeditwinstart<0)
|
|
|
|
{
|
|
|
|
osdeditwinstart=0;
|
|
|
|
osdeditwinend = editlinewidth;
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 6: // control f, move one character right
|
2008-07-08 04:52:39 +00:00
|
|
|
if (osdeditcursor < osdeditlen) osdeditcursor++;
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 8:
|
2010-05-18 05:14:17 +00:00
|
|
|
// case 127: // control h, backspace
|
2008-07-04 02:13:48 +00:00
|
|
|
if (!osdeditcursor || !osdeditlen) return 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
if ((osdflags & OSD_OVERTYPE) == 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-07-04 02:13:48 +00:00
|
|
|
if (osdeditcursor < osdeditlen)
|
|
|
|
Bmemmove(osdeditbuf+osdeditcursor-1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
|
|
|
|
osdeditlen--;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2008-07-04 02:13:48 +00:00
|
|
|
osdeditcursor--;
|
|
|
|
if (osdeditcursor<osdeditwinstart) osdeditwinstart--,osdeditwinend--;
|
2010-05-18 05:14:17 +00:00
|
|
|
case 127: // handled in OSD_HandleScanCode (delete)
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 9: // tab
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
int32_t commonsize = 512;
|
2008-07-01 10:31:03 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (!lastmatch)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
for (i=osdeditcursor; i>0; i--) if (osdeditbuf[i-1] == ' ') break;
|
|
|
|
for (j=0; osdeditbuf[i] != ' ' && i < osdeditlen; j++,i++)
|
|
|
|
osdedittmp[j] = osdeditbuf[i];
|
|
|
|
osdedittmp[j] = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (j > 0)
|
2006-12-11 03:06:49 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
tabc = findsymbol(osdedittmp, NULL);
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (tabc && tabc->next && findsymbol(osdedittmp, tabc->next))
|
2006-12-11 03:06:49 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
symbol_t *symb=tabc;
|
|
|
|
int32_t maxwidth = 0, x = 0, num = 0, diffpt;
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
while (symb && symb != lastmatch)
|
2008-07-09 09:34:12 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
num++;
|
|
|
|
|
|
|
|
if (lastmatch)
|
|
|
|
{
|
|
|
|
diffpt = OSD_FindDiffPoint(symb->name,lastmatch->name);
|
|
|
|
if (diffpt < commonsize)
|
|
|
|
commonsize = diffpt;
|
|
|
|
}
|
|
|
|
|
|
|
|
maxwidth = max((unsigned)maxwidth,Bstrlen(symb->name));
|
|
|
|
lastmatch = symb;
|
|
|
|
if (!lastmatch->next) break;
|
|
|
|
symb=findsymbol(osdedittmp, lastmatch->next);
|
2008-07-09 09:34:12 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_Printf(OSDTEXT_RED "Found %d possible completions for '%s':\n",num,osdedittmp);
|
|
|
|
maxwidth += 3;
|
|
|
|
symb = tabc;
|
|
|
|
OSD_Printf(" ");
|
|
|
|
while (symb && (symb != lastmatch))
|
2008-07-09 09:34:12 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
tabc = lastmatch = symb;
|
|
|
|
OSD_Printf("%-*s",maxwidth,symb->name);
|
|
|
|
if (!lastmatch->next) break;
|
|
|
|
symb=findsymbol(osdedittmp, lastmatch->next);
|
|
|
|
x += maxwidth;
|
|
|
|
if (x > (osdcols - maxwidth))
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
OSD_Printf("\n");
|
|
|
|
if (symb && (symb != lastmatch))
|
|
|
|
OSD_Printf(" ");
|
|
|
|
}
|
2006-12-11 03:06:49 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
if (x) OSD_Printf("\n");
|
|
|
|
OSD_Printf(OSDTEXT_RED "Press TAB again to cycle through matches\n");
|
2006-12-11 03:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
else
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
tabc = findsymbol(osdedittmp, lastmatch->next);
|
|
|
|
if (!tabc && lastmatch)
|
|
|
|
tabc = findsymbol(osdedittmp, NULL); // wrap */
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (tabc)
|
|
|
|
{
|
|
|
|
for (i=osdeditcursor; i>0; i--) if (osdeditbuf[i-1] == ' ') break;
|
|
|
|
osdeditlen = i;
|
|
|
|
for (j=0; tabc->name[j] && osdeditlen <= EDITLENGTH
|
|
|
|
&& (osdeditlen < commonsize); i++,j++,osdeditlen++)
|
|
|
|
osdeditbuf[i] = tabc->name[j];
|
|
|
|
osdeditcursor = osdeditlen;
|
|
|
|
osdeditwinend = osdeditcursor;
|
|
|
|
osdeditwinstart = osdeditwinend-editlinewidth;
|
|
|
|
if (osdeditwinstart<0)
|
|
|
|
{
|
|
|
|
osdeditwinstart=0;
|
|
|
|
osdeditwinend = editlinewidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
lastmatch = tabc;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 11: // control k, delete all to end of line
|
2008-07-08 04:52:39 +00:00
|
|
|
Bmemset(osdeditbuf+osdeditcursor,0,sizeof(osdeditbuf)-osdeditcursor);
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 12: // control l, clear screen
|
2008-07-04 02:13:48 +00:00
|
|
|
Bmemset(osdtext,0,sizeof(osdtext));
|
2008-07-18 13:18:12 +00:00
|
|
|
Bmemset(osdfmt,osdtextpal+(osdtextshade<<5),sizeof(osdfmt));
|
2008-07-04 02:13:48 +00:00
|
|
|
osdlines = 1;
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 13: // control m, enter
|
2008-07-04 02:13:48 +00:00
|
|
|
if (osdeditlen>0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-07-04 02:13:48 +00:00
|
|
|
osdeditbuf[osdeditlen] = 0;
|
2008-07-07 12:17:27 +00:00
|
|
|
if (Bstrcmp(osdhistorybuf[0], osdeditbuf))
|
|
|
|
{
|
|
|
|
Bmemmove(osdhistorybuf[1], osdhistorybuf[0], (HISTORYDEPTH-1)*(EDITLENGTH+1));
|
|
|
|
Bmemmove(osdhistorybuf[0], osdeditbuf, EDITLENGTH+1);
|
|
|
|
if (osdhistorysize < HISTORYDEPTH) osdhistorysize++;
|
2008-07-07 12:35:21 +00:00
|
|
|
osdhistorytotal++;
|
2008-07-07 12:17:27 +00:00
|
|
|
if (osdexeccount == HISTORYDEPTH)
|
|
|
|
OSD_Printf("Command Buffer Warning: Failed queueing command "
|
2010-05-02 23:27:30 +00:00
|
|
|
"for execution. Buffer full.\n");
|
2008-07-07 12:17:27 +00:00
|
|
|
else
|
|
|
|
osdexeccount++;
|
|
|
|
}
|
2008-07-04 02:13:48 +00:00
|
|
|
else
|
2008-07-07 12:17:27 +00:00
|
|
|
{
|
|
|
|
if (osdexeccount == HISTORYDEPTH)
|
|
|
|
OSD_Printf("Command Buffer Warning: Failed queueing command "
|
2010-05-02 23:27:30 +00:00
|
|
|
"for execution. Buffer full.\n");
|
2008-07-07 12:17:27 +00:00
|
|
|
else
|
|
|
|
osdexeccount++;
|
|
|
|
}
|
2008-07-04 02:13:48 +00:00
|
|
|
osdhistorypos=-1;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2008-07-04 02:13:48 +00:00
|
|
|
|
|
|
|
osdeditlen=0;
|
|
|
|
osdeditcursor=0;
|
|
|
|
osdeditwinstart=0;
|
|
|
|
osdeditwinend=editlinewidth;
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 14: // control n, next (ie. down arrow)
|
2008-07-08 04:52:39 +00:00
|
|
|
OSD_HistoryNext();
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 16: // control p, previous (ie. up arrow)
|
2008-07-08 04:52:39 +00:00
|
|
|
OSD_HistoryPrev();
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 21: // control u, delete all to beginning
|
2008-07-04 02:13:48 +00:00
|
|
|
if (osdeditcursor>0 && osdeditlen)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-07-04 02:13:48 +00:00
|
|
|
if (osdeditcursor<osdeditlen)
|
|
|
|
Bmemmove(osdeditbuf, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
|
|
|
|
osdeditlen-=osdeditcursor;
|
|
|
|
osdeditcursor = 0;
|
|
|
|
osdeditwinstart = 0;
|
|
|
|
osdeditwinend = editlinewidth;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
case 23: // control w, delete one word back
|
2008-07-04 02:13:48 +00:00
|
|
|
if (osdeditcursor>0 && osdeditlen>0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-07-04 02:13:48 +00:00
|
|
|
i=osdeditcursor;
|
2010-05-02 23:27:30 +00:00
|
|
|
while (i>0 && osdeditbuf[i-1]==asc_Space) i--;
|
|
|
|
while (i>0 && osdeditbuf[i-1]!=asc_Space) i--;
|
2008-07-04 02:13:48 +00:00
|
|
|
if (osdeditcursor<osdeditlen)
|
|
|
|
Bmemmove(osdeditbuf+i, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
|
|
|
|
osdeditlen -= (osdeditcursor-i);
|
|
|
|
osdeditcursor = i;
|
|
|
|
if (osdeditcursor < osdeditwinstart)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-07-04 02:13:48 +00:00
|
|
|
osdeditwinstart=osdeditcursor;
|
|
|
|
osdeditwinend=osdeditwinstart+editlinewidth;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
if (ch >= asc_Space) // text char
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if ((osdflags & OSD_OVERTYPE) == 0)
|
|
|
|
{
|
|
|
|
if (osdeditlen == EDITLENGTH) // buffer full, can't insert another char
|
|
|
|
return 0;
|
|
|
|
if (osdeditcursor < osdeditlen)
|
|
|
|
Bmemmove(osdeditbuf+osdeditcursor+1, osdeditbuf+osdeditcursor, osdeditlen-osdeditcursor);
|
|
|
|
osdeditlen++;
|
|
|
|
}
|
|
|
|
else if (osdeditcursor == osdeditlen)
|
2006-04-24 19:04:22 +00:00
|
|
|
osdeditlen++;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
|
|
|
osdeditbuf[osdeditcursor++] = ch;
|
|
|
|
|
|
|
|
if (osdeditcursor > osdeditwinend)
|
|
|
|
osdeditwinstart++, osdeditwinend++;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2008-07-02 01:32:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_HandleScanCode(int32_t sc, int32_t press)
|
2008-07-02 01:32:53 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if ((osdflags & OSD_INITIALIZED) == 0)
|
|
|
|
return sc;
|
2008-07-02 01:32:53 +00:00
|
|
|
|
|
|
|
if (sc == osdkey)
|
|
|
|
{
|
|
|
|
if (press)
|
|
|
|
{
|
|
|
|
osdscroll = -osdscroll;
|
|
|
|
if (osdrowscur == -1)
|
|
|
|
osdscroll = 1;
|
|
|
|
else if (osdrowscur == osdrows)
|
|
|
|
osdscroll = -1;
|
|
|
|
osdrowscur += osdscroll;
|
|
|
|
OSD_CaptureInput(osdscroll == 1);
|
|
|
|
osdscrtime = getticks();
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
2008-07-02 01:32:53 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
else if ((osdflags & OSD_CAPTURE) == 0)
|
2008-07-02 01:32:53 +00:00
|
|
|
return sc;
|
|
|
|
|
|
|
|
if (!press)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (sc == sc_LeftShift || sc == sc_RightShift)
|
|
|
|
osdflags &= ~OSD_SHIFT;
|
|
|
|
if (sc == sc_LeftControl || sc == sc_RightControl)
|
|
|
|
osdflags &= ~OSD_CTRL;
|
|
|
|
return 0;
|
2008-07-02 01:32:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
keytime = gettime();
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
switch (sc)
|
2007-12-20 19:14:38 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_Escape:
|
2007-12-12 17:42:14 +00:00
|
|
|
// OSD_ShowDisplay(0);
|
|
|
|
osdscroll = -1;
|
2010-05-02 23:27:30 +00:00
|
|
|
osdrowscur--;
|
2007-12-12 17:42:14 +00:00
|
|
|
OSD_CaptureInput(0);
|
|
|
|
osdscrtime = getticks();
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
|
|
|
case sc_PgUp:
|
2006-04-24 19:04:22 +00:00
|
|
|
if (osdhead < osdlines-1)
|
|
|
|
osdhead++;
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
|
|
|
case sc_PgDn:
|
2006-04-24 19:04:22 +00:00
|
|
|
if (osdhead > 0)
|
|
|
|
osdhead--;
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
|
|
|
case sc_Home:
|
|
|
|
if (osdflags & OSD_CTRL)
|
2006-04-24 19:04:22 +00:00
|
|
|
osdhead = osdlines-1;
|
2007-12-12 17:42:14 +00:00
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
osdeditcursor = 0;
|
|
|
|
osdeditwinstart = osdeditcursor;
|
|
|
|
osdeditwinend = osdeditwinstart+editlinewidth;
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
|
|
|
case sc_End:
|
|
|
|
if (osdflags & OSD_CTRL)
|
2006-04-24 19:04:22 +00:00
|
|
|
osdhead = 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
osdeditcursor = osdeditlen;
|
|
|
|
osdeditwinend = osdeditcursor;
|
|
|
|
osdeditwinstart = osdeditwinend-editlinewidth;
|
2007-12-12 17:42:14 +00:00
|
|
|
if (osdeditwinstart<0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
osdeditwinstart=0;
|
|
|
|
osdeditwinend = editlinewidth;
|
|
|
|
}
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
|
|
|
case sc_Insert:
|
2010-05-18 05:14:17 +00:00
|
|
|
osdflags = (osdflags & ~OSD_OVERTYPE) | (-((osdflags & OSD_OVERTYPE) == 0) & OSD_OVERTYPE);
|
|
|
|
break;
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_LeftArrow:
|
2007-12-12 17:42:14 +00:00
|
|
|
if (osdeditcursor>0)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (osdflags & OSD_CTRL)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
while (osdeditcursor>0)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (osdeditbuf[osdeditcursor-1] != asc_Space)
|
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
osdeditcursor--;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
while (osdeditcursor>0)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (osdeditbuf[osdeditcursor-1] == asc_Space)
|
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
osdeditcursor--;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else osdeditcursor--;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
if (osdeditcursor<osdeditwinstart)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
|
|
|
osdeditwinend-=(osdeditwinstart-osdeditcursor);
|
|
|
|
osdeditwinstart-=(osdeditwinstart-osdeditcursor);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sc_RightArrow:
|
2007-12-12 17:42:14 +00:00
|
|
|
if (osdeditcursor<osdeditlen)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (osdflags & OSD_CTRL)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
|
|
|
while (osdeditcursor<osdeditlen)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (osdeditbuf[osdeditcursor] == asc_Space)
|
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
osdeditcursor++;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
while (osdeditcursor<osdeditlen)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (osdeditbuf[osdeditcursor] != asc_Space)
|
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
osdeditcursor++;
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else osdeditcursor++;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
if (osdeditcursor>=osdeditwinend)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
|
|
|
osdeditwinstart+=(osdeditcursor-osdeditwinend);
|
|
|
|
osdeditwinend+=(osdeditcursor-osdeditwinend);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sc_UpArrow:
|
2008-07-08 04:52:39 +00:00
|
|
|
OSD_HistoryPrev();
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
|
|
|
case sc_DownArrow:
|
2008-07-08 04:52:39 +00:00
|
|
|
OSD_HistoryNext();
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
|
|
|
case sc_LeftShift:
|
|
|
|
case sc_RightShift:
|
|
|
|
osdflags |= OSD_SHIFT;
|
|
|
|
break;
|
|
|
|
case sc_LeftControl:
|
|
|
|
case sc_RightControl:
|
|
|
|
osdflags |= OSD_CTRL;
|
|
|
|
break;
|
|
|
|
case sc_CapsLock:
|
|
|
|
osdflags = (osdflags & ~OSD_CAPS) | (-((osdflags & OSD_CAPS) == 0) & OSD_CAPS);
|
|
|
|
break;
|
|
|
|
case sc_Delete:
|
|
|
|
if (osdeditcursor == osdeditlen || !osdeditlen)
|
|
|
|
return 0;
|
|
|
|
if (osdeditcursor <= osdeditlen-1)
|
|
|
|
Bmemmove(osdeditbuf+osdeditcursor, osdeditbuf+osdeditcursor+1, osdeditlen-osdeditcursor-1);
|
2006-04-24 19:04:22 +00:00
|
|
|
osdeditlen--;
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_ResizeDisplay() -- Handles readjustment of the display when the screen resolution
|
2008-08-23 15:37:30 +00:00
|
|
|
// changes on us.
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
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
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t newcols;
|
|
|
|
int32_t newmaxlines;
|
2006-04-24 19:04:22 +00:00
|
|
|
char newtext[TEXTSIZE];
|
2008-07-18 09:50:44 +00:00
|
|
|
char newfmt[TEXTSIZE];
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i,j,k;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
newcols = getcolumnwidth(w);
|
|
|
|
newmaxlines = TEXTSIZE / newcols;
|
|
|
|
|
|
|
|
j = min(newmaxlines, osdmaxlines);
|
|
|
|
k = min(newcols, osdcols);
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
Bmemset(newtext, asc_Space, TEXTSIZE);
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=j-1; i>=0; i--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(newtext+newcols*i, osdtext+osdcols*i, k);
|
|
|
|
Bmemcpy(newfmt+newcols*i, osdfmt+osdcols*i, k);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2009-06-09 06:19:58 +00:00
|
|
|
Bmemcpy(osdtext, newtext, TEXTSIZE);
|
|
|
|
Bmemcpy(osdfmt, newfmt, TEXTSIZE);
|
2006-04-24 19:04:22 +00:00
|
|
|
osdcols = newcols;
|
|
|
|
osdmaxlines = newmaxlines;
|
|
|
|
osdmaxrows = getrowheight(h)-2;
|
|
|
|
|
|
|
|
if (osdrows > osdmaxrows) osdrows = osdmaxrows;
|
|
|
|
|
|
|
|
osdpos = 0;
|
|
|
|
osdhead = 0;
|
|
|
|
osdeditwinstart = 0;
|
|
|
|
osdeditwinend = editlinewidth;
|
|
|
|
white = -1;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2006-12-11 03:32:43 +00:00
|
|
|
// OSD_CaptureInput()
|
2006-04-13 20:47:06 +00:00
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
void OSD_CaptureInput(int32_t cap)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2010-05-18 05:14:17 +00:00
|
|
|
osdflags = (osdflags & ~(OSD_CAPTURE|OSD_CTRL|OSD_SHIFT)) | (-cap & OSD_CAPTURE);
|
2010-05-02 23:27:30 +00:00
|
|
|
|
|
|
|
grabmouse(cap == 0);
|
|
|
|
onshowosd(cap);
|
|
|
|
|
|
|
|
if (cap)
|
|
|
|
releaseallbuttons();
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-12-11 21:18:21 +00:00
|
|
|
bflushchars();
|
2006-12-11 03:32:43 +00:00
|
|
|
}
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2006-12-11 03:32:43 +00:00
|
|
|
//
|
|
|
|
// OSD_ShowDisplay() -- Shows or hides the onscreen display
|
|
|
|
//
|
2009-01-09 09:29:17 +00:00
|
|
|
void OSD_ShowDisplay(int32_t onf)
|
2006-12-11 03:32:43 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
osdflags = (osdflags & ~OSD_DRAW) | (-onf & OSD_DRAW);
|
|
|
|
OSD_CaptureInput(onf);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_Draw() -- Draw the onscreen display
|
|
|
|
//
|
2007-01-02 02:27:31 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
void OSD_Draw(void)
|
|
|
|
{
|
2009-06-05 20:09:13 +00:00
|
|
|
uint32_t topoffs;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t row, lines, x, len;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if ((osdflags & OSD_INITIALIZED) == 0)
|
|
|
|
return;
|
2006-12-11 03:06:49 +00:00
|
|
|
|
2006-12-11 21:18:21 +00:00
|
|
|
if (osdrowscur == 0)
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_ShowDisplay(osdflags & OSD_DRAW ? 0 : 1);
|
2006-12-11 03:06:49 +00:00
|
|
|
|
|
|
|
if (osdrowscur == osdrows)
|
|
|
|
osdscroll = 0;
|
|
|
|
else
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t j;
|
2007-12-12 17:42:14 +00:00
|
|
|
|
2006-12-11 21:18:21 +00:00
|
|
|
if ((osdrowscur < osdrows && osdscroll == 1) || osdrowscur < -1)
|
2007-01-06 09:50:02 +00:00
|
|
|
{
|
2007-01-12 05:05:19 +00:00
|
|
|
j = (getticks()-osdscrtime);
|
2007-01-06 09:50:02 +00:00
|
|
|
while (j > -1)
|
|
|
|
{
|
|
|
|
osdrowscur++;
|
2008-01-04 01:04:35 +00:00
|
|
|
j -= 200/osdrows;
|
2007-01-06 09:50:02 +00:00
|
|
|
if (osdrowscur > osdrows-1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-01-02 02:27:31 +00:00
|
|
|
if ((osdrowscur > -1 && osdscroll == -1) || osdrowscur > osdrows)
|
2007-01-06 09:50:02 +00:00
|
|
|
{
|
2007-01-12 05:05:19 +00:00
|
|
|
j = (getticks()-osdscrtime);
|
2007-01-06 09:50:02 +00:00
|
|
|
while (j > -1)
|
|
|
|
{
|
|
|
|
osdrowscur--;
|
2008-01-04 01:04:35 +00:00
|
|
|
j -= 200/osdrows;
|
2007-01-06 09:50:02 +00:00
|
|
|
if (osdrowscur < 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
osdscrtime = getticks();
|
2007-01-02 02:27:31 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if ((osdflags & OSD_DRAW) == 0 || !osdrowscur) return;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
topoffs = osdhead * osdcols;
|
2006-12-11 03:06:49 +00:00
|
|
|
row = osdrowscur-1;
|
2007-12-12 17:42:14 +00:00
|
|
|
lines = min(osdlines-osdhead, osdrowscur);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
begindrawing();
|
|
|
|
|
2006-12-11 03:06:49 +00:00
|
|
|
clearbackground(osdcols,osdrowscur+1);
|
2007-12-12 17:42:14 +00:00
|
|
|
|
2010-05-22 14:04:47 +00:00
|
|
|
if (osdver[0] && osdrowscur>2)
|
|
|
|
drawosdstr(osdcols-osdverlen,osdrowscur-2,osdver,osdverlen,(sintable[(totalclock<<4)&2047]>>11),osdverpal);
|
2007-12-12 17:42:14 +00:00
|
|
|
|
|
|
|
for (; lines>0; lines--, row--)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
drawosdstr(0,row,osdtext+topoffs,osdcols,osdtextshade,osdtextpal);
|
|
|
|
topoffs+=osdcols;
|
|
|
|
}
|
|
|
|
|
2008-10-11 09:20:04 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
int32_t offset = ((osdflags & (OSD_CAPS|OSD_SHIFT)) == (OSD_CAPS|OSD_SHIFT) && osdhead > 0);
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t shade = osdpromptshade?osdpromptshade:(sintable[(totalclock<<4)&2047]>>11);
|
2008-10-11 09:20:04 +00:00
|
|
|
|
|
|
|
if (osdhead == osdlines-1) drawosdchar(0,osdrowscur,'~',shade,osdpromptpal);
|
|
|
|
else if (osdhead > 0) drawosdchar(0,osdrowscur,'^',shade,osdpromptpal);
|
2010-05-02 23:27:30 +00:00
|
|
|
if (osdflags & OSD_CAPS) drawosdchar(0+(osdhead > 0),osdrowscur,'C',shade,osdpromptpal);
|
|
|
|
if (osdflags & OSD_SHIFT) drawosdchar(1+(osdflags & OSD_CAPS && osdhead > 0),osdrowscur,'H',shade,osdpromptpal);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-10-11 09:20:04 +00:00
|
|
|
drawosdchar(2+offset,osdrowscur,'>',shade,osdpromptpal);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2008-10-11 09:20:04 +00:00
|
|
|
len = min(osdcols-1-3-offset, osdeditlen-osdeditwinstart);
|
|
|
|
for (x=len-1; x>=0; x--)
|
|
|
|
drawosdchar(3+x+offset,osdrowscur,osdeditbuf[osdeditwinstart+x],osdeditshade<<1,osdeditpal);
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
drawosdcursor(3+osdeditcursor-osdeditwinstart+offset,osdrowscur,osdflags & OSD_OVERTYPE,keytime);
|
2008-10-11 09:20:04 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
enddrawing();
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_Printf() -- Print a string to the onscreen display
|
|
|
|
// and write it to the log file
|
|
|
|
//
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
static inline void OSD_LineFeed(void)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
Bmemmove(osdtext+osdcols, osdtext, TEXTSIZE-osdcols);
|
2010-05-02 23:27:30 +00:00
|
|
|
Bmemset(osdtext, asc_Space, osdcols);
|
2008-07-18 09:50:44 +00:00
|
|
|
Bmemmove(osdfmt+osdcols, osdfmt, TEXTSIZE-osdcols);
|
|
|
|
Bmemset(osdfmt, osdtextpal, osdcols);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (osdlines < osdmaxlines) osdlines++;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2008-08-23 15:37:30 +00:00
|
|
|
#define MAX_ERRORS 4096
|
2006-04-13 20:47:06 +00:00
|
|
|
void OSD_Printf(const char *fmt, ...)
|
|
|
|
{
|
2009-04-14 13:58:38 +00:00
|
|
|
static char tmpstr[8192];
|
2008-08-03 11:45:15 +00:00
|
|
|
char *chp, p=osdtextpal, s=osdtextshade;
|
2006-04-24 19:04:22 +00:00
|
|
|
va_list va;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if ((osdflags & OSD_INITIALIZED) == 0)
|
|
|
|
OSD_Init();
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
va_start(va, fmt);
|
2009-04-14 13:58:38 +00:00
|
|
|
Bvsnprintf(tmpstr, 8192, fmt, va);
|
2006-04-24 19:04:22 +00:00
|
|
|
va_end(va);
|
|
|
|
|
2008-08-23 15:37:30 +00:00
|
|
|
if (tmpstr[0]=='^' && tmpstr[1]=='1' && tmpstr[2]=='0' && ++OSD_errors > MAX_ERRORS)
|
|
|
|
{
|
2008-08-24 06:17:09 +00:00
|
|
|
if (OSD_errors == MAX_ERRORS+1) Bstrcpy(tmpstr,OSD_ERROR "\nToo many errors. Logging errors stopped.\n");
|
|
|
|
else
|
|
|
|
{
|
|
|
|
OSD_errors=MAX_ERRORS+2;
|
|
|
|
return;
|
|
|
|
}
|
2008-08-23 15:37:30 +00:00
|
|
|
}
|
|
|
|
|
2008-05-10 01:29:37 +00:00
|
|
|
if (linecnt<logcutoff)
|
2008-01-04 01:04:35 +00:00
|
|
|
{
|
|
|
|
if (osdlog&&(!logcutoff||linecnt<logcutoff))
|
2008-08-03 11:45:15 +00:00
|
|
|
{
|
|
|
|
chp = Bstrdup(tmpstr);
|
2010-05-02 23:27:30 +00:00
|
|
|
Bfputs(OSD_StripColors(chp,tmpstr), osdlog);
|
2008-08-03 11:45:15 +00:00
|
|
|
Bfree(chp);
|
|
|
|
}
|
2008-01-04 01:04:35 +00:00
|
|
|
}
|
2008-05-10 01:29:37 +00:00
|
|
|
else if (linecnt==logcutoff)
|
2008-01-04 01:04:35 +00:00
|
|
|
{
|
|
|
|
Bfputs("\nMaximal log size reached. Logging stopped.\nSet the \"logcutoff\" console variable to a higher value if you need a longer log.\n", osdlog);
|
|
|
|
linecnt=logcutoff+1;
|
|
|
|
}
|
|
|
|
|
2008-08-24 05:39:28 +00:00
|
|
|
chp = tmpstr;
|
|
|
|
do
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-08-24 05:39:28 +00:00
|
|
|
if (*chp == '\n')
|
|
|
|
{
|
|
|
|
osdpos=0;
|
|
|
|
linecnt++;
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_LineFeed();
|
2008-08-24 05:39:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*chp == '\r')
|
|
|
|
{
|
|
|
|
osdpos=0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (*chp == '^')
|
2008-07-18 09:50:44 +00:00
|
|
|
{
|
|
|
|
if (isdigit(*(chp+1)))
|
|
|
|
{
|
2008-08-24 05:39:28 +00:00
|
|
|
char smallbuf[4];
|
2008-08-24 09:29:03 +00:00
|
|
|
if (!isdigit(*(++chp+1)))
|
2008-08-24 05:39:28 +00:00
|
|
|
{
|
|
|
|
smallbuf[0] = *(chp);
|
|
|
|
smallbuf[1] = '\0';
|
|
|
|
p = atol(smallbuf);
|
2008-08-24 09:29:03 +00:00
|
|
|
continue;
|
2008-08-24 05:39:28 +00:00
|
|
|
}
|
2008-08-24 09:29:03 +00:00
|
|
|
smallbuf[0] = *(chp++);
|
|
|
|
smallbuf[1] = *(chp);
|
|
|
|
smallbuf[2] = '\0';
|
|
|
|
p = atol(smallbuf);
|
2008-08-24 05:39:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (Btoupper(*(chp+1)) == 'S')
|
|
|
|
{
|
|
|
|
chp++;
|
|
|
|
if (isdigit(*(++chp)))
|
|
|
|
s = *chp;
|
|
|
|
continue;
|
2008-07-18 09:50:44 +00:00
|
|
|
}
|
2008-08-24 05:39:28 +00:00
|
|
|
if (Btoupper(*(chp+1)) == 'O')
|
2008-07-18 09:50:44 +00:00
|
|
|
{
|
2008-08-24 05:39:28 +00:00
|
|
|
chp++;
|
|
|
|
p = osdtextpal;
|
|
|
|
s = osdtextshade;
|
|
|
|
continue;
|
2008-07-18 09:50:44 +00:00
|
|
|
}
|
|
|
|
}
|
2008-08-24 05:39:28 +00:00
|
|
|
osdtext[osdpos] = *chp;
|
|
|
|
osdfmt[osdpos++] = p+(s<<5);
|
|
|
|
if (osdpos == osdcols)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2008-08-24 05:39:28 +00:00
|
|
|
osdpos = 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_LineFeed();
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
|
|
|
while (*(++chp));
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_DispatchQueued() -- Executes any commands queued in the buffer
|
|
|
|
//
|
|
|
|
void OSD_DispatchQueued(void)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t cmd;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!osdexeccount) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
cmd=osdexeccount-1;
|
|
|
|
osdexeccount=0;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (; cmd>=0; cmd--)
|
2006-04-24 19:04:22 +00:00
|
|
|
OSD_Dispatch((const char *)osdhistorybuf[cmd]);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_Dispatch() -- Executes a command string
|
|
|
|
//
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static char *strtoken(char *s, char **ptrptr, int32_t *restart)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char *p, *p2, *start;
|
|
|
|
|
|
|
|
*restart = 0;
|
|
|
|
if (!ptrptr) return NULL;
|
|
|
|
|
|
|
|
// if s != NULL, we process from the start of s, otherwise
|
|
|
|
// we just continue with where ptrptr points to
|
|
|
|
if (s) p = s;
|
|
|
|
else p = *ptrptr;
|
|
|
|
|
|
|
|
if (!p) return NULL;
|
|
|
|
|
|
|
|
// eat up any leading whitespace
|
|
|
|
while (*p != 0 && *p != ';' && *p == ' ') p++;
|
|
|
|
|
|
|
|
// a semicolon is an end of statement delimiter like a \0 is, so we signal
|
|
|
|
// the caller to 'restart' for the rest of the string pointed at by *ptrptr
|
2007-12-12 17:42:14 +00:00
|
|
|
if (*p == ';')
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
*restart = 1;
|
|
|
|
*ptrptr = p+1;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
// or if we hit the end of the input, signal all done by nulling *ptrptr
|
2007-12-12 17:42:14 +00:00
|
|
|
else if (*p == 0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
*ptrptr = NULL;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (*p == '\"')
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// quoted string
|
|
|
|
start = ++p;
|
|
|
|
p2 = p;
|
2007-12-12 17:42:14 +00:00
|
|
|
while (*p != 0)
|
|
|
|
{
|
|
|
|
if (*p == '\"')
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
p++;
|
|
|
|
break;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else if (*p == '\\')
|
|
|
|
{
|
|
|
|
switch (*(++p))
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
case 'n':
|
|
|
|
*p2 = '\n'; break;
|
|
|
|
case 'r':
|
|
|
|
*p2 = '\r'; break;
|
|
|
|
default:
|
|
|
|
*p2 = *p; break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
*p2 = *p;
|
|
|
|
}
|
|
|
|
p2++, p++;
|
|
|
|
}
|
|
|
|
*p2 = 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
start = p;
|
|
|
|
while (*p != 0 && *p != ';' && *p != ' ') p++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we hit the end of input, signal all done by nulling *ptrptr
|
2007-12-12 17:42:14 +00:00
|
|
|
if (*p == 0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
*ptrptr = NULL;
|
|
|
|
}
|
|
|
|
// or if we came upon a semicolon, signal caller to restart with the
|
|
|
|
// string at *ptrptr
|
2007-12-12 17:42:14 +00:00
|
|
|
else if (*p == ';')
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
*p = 0;
|
|
|
|
*ptrptr = p+1;
|
|
|
|
*restart = 1;
|
|
|
|
}
|
|
|
|
// otherwise, clip off the token and carry on
|
2007-12-12 17:42:14 +00:00
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
*(p++) = 0;
|
|
|
|
*ptrptr = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
return start;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MAXPARMS 512
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_Dispatch(const char *cmd)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char *workbuf, *wp, *wtp, *state;
|
2010-05-09 08:51:25 +00:00
|
|
|
int32_t restart = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
workbuf = state = Bstrdup(cmd);
|
|
|
|
if (!workbuf) return -1;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
do
|
|
|
|
{
|
2010-05-09 08:51:25 +00:00
|
|
|
int32_t numparms = 0;
|
|
|
|
symbol_t *symb;
|
|
|
|
osdfuncparm_t ofp;
|
|
|
|
char *parms[MAXPARMS];
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
Bmemset(parms, 0, sizeof(parms));
|
2010-05-09 08:51:25 +00:00
|
|
|
|
|
|
|
if ((wp = strtoken(state, &wtp, &restart)) == NULL)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
state = wtp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-05-09 08:51:25 +00:00
|
|
|
if ((symb = findexactsymbol(wp)) == NULL)
|
2008-06-29 12:53:18 +00:00
|
|
|
{
|
2010-05-09 08:51:25 +00:00
|
|
|
if (wp[0] != '/' || wp[1] != '/') // cheap hack for comments in cfgs
|
|
|
|
OSD_Printf(OSDTEXT_RED "\"%s\" is not a valid command or cvar\n", wp);
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(workbuf);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofp.name = wp;
|
2007-12-12 17:42:14 +00:00
|
|
|
while (wtp && !restart)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
wp = strtoken(NULL, &wtp, &restart);
|
|
|
|
if (wp && numparms < MAXPARMS) parms[numparms++] = wp;
|
|
|
|
}
|
|
|
|
ofp.numparms = numparms;
|
|
|
|
ofp.parms = (const char **)parms;
|
|
|
|
ofp.raw = cmd;
|
2010-05-09 08:51:25 +00:00
|
|
|
|
|
|
|
switch((intptr_t)symb->func)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-09 08:51:25 +00:00
|
|
|
case (intptr_t)OSD_ALIAS:
|
|
|
|
OSD_Dispatch(symb->help);
|
|
|
|
case (intptr_t)OSD_UNALIASED:
|
|
|
|
break;
|
|
|
|
default:
|
2008-06-30 00:18:59 +00:00
|
|
|
switch (symb->func(&ofp))
|
|
|
|
{
|
|
|
|
case OSDCMD_OK:
|
|
|
|
break;
|
|
|
|
case OSDCMD_SHOWHELP:
|
|
|
|
OSD_Printf("%s\n", symb->help);
|
|
|
|
break;
|
|
|
|
}
|
2010-05-09 08:51:25 +00:00
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
state = wtp;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
while (wtp && restart);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(workbuf);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_RegisterFunction() -- Registers a new 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
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
symbol_t *symb;
|
|
|
|
const char *cp;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if ((osdflags & OSD_INITIALIZED) == 0)
|
|
|
|
OSD_Init();
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2010-05-07 20:45:40 +00:00
|
|
|
if (!name || !name[0])
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-07 20:45:40 +00:00
|
|
|
OSD_Printf("OSD_RegisterFunction(): can't register function with null name\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2010-05-07 20:45:40 +00:00
|
|
|
|
|
|
|
if (!func)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-07 20:45:40 +00:00
|
|
|
OSD_Printf("OSD_RegisterFunction(): can't register null function\n");
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for illegal characters in name
|
2007-12-12 17:42:14 +00:00
|
|
|
for (cp = name; *cp; cp++)
|
|
|
|
{
|
|
|
|
if ((cp == name) && (*cp >= '0') && (*cp <= '9'))
|
|
|
|
{
|
2008-06-29 22:37:30 +00:00
|
|
|
OSD_Printf("OSD_RegisterFunction(): first character of function name \"%s\" must not be a numeral\n", name);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((*cp < '0') ||
|
|
|
|
(*cp > '9' && *cp < 'A') ||
|
|
|
|
(*cp > 'Z' && *cp < 'a' && *cp != '_') ||
|
2007-12-12 17:42:14 +00:00
|
|
|
(*cp > 'z'))
|
|
|
|
{
|
2008-06-29 22:37:30 +00:00
|
|
|
OSD_Printf("OSD_RegisterFunction(): illegal character in function name \"%s\"\n", name);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!help) help = "(no description for this function)";
|
|
|
|
|
|
|
|
symb = findexactsymbol(name);
|
2010-05-07 20:45:40 +00:00
|
|
|
|
2008-06-29 22:37:30 +00:00
|
|
|
if (symb) // allow this now for reusing an alias name
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (symb->func != OSD_ALIAS && symb->func != OSD_UNALIASED)
|
2008-06-30 00:18:59 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("OSD_RegisterFunction(): \"%s\" is already defined\n", name);
|
|
|
|
return -1;
|
|
|
|
}
|
2008-06-30 00:32:05 +00:00
|
|
|
Bfree((char *)symb->help);
|
2008-06-29 22:37:30 +00:00
|
|
|
symb->help = help;
|
2008-06-30 01:03:51 +00:00
|
|
|
symb->func = func;
|
2008-06-30 00:32:05 +00:00
|
|
|
return 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
symb = addnewsymbol(name);
|
2010-05-07 20:45:40 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!symb)
|
|
|
|
{
|
2008-06-29 22:37:30 +00:00
|
|
|
OSD_Printf("OSD_RegisterFunction(): Failed registering function \"%s\"\n", name);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
symb->name = name;
|
|
|
|
symb->help = help;
|
|
|
|
symb->func = func;
|
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2006-12-11 04:38:10 +00:00
|
|
|
//
|
|
|
|
// OSD_SetVersionString()
|
|
|
|
//
|
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
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
Bstrcpy(osdver,version);
|
|
|
|
osdverlen = Bstrlen(osdver);
|
|
|
|
osdvershade = shade;
|
|
|
|
osdverpal = pal;
|
2006-12-11 04:38:10 +00:00
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// addnewsymbol() -- Allocates space for a new symbol and attaches it
|
|
|
|
// appropriately to the lists, sorted.
|
|
|
|
//
|
2008-08-25 02:12:02 +00:00
|
|
|
|
2006-04-13 20:47:06 +00:00
|
|
|
static symbol_t *addnewsymbol(const char *name)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
symbol_t *newsymb, *s, *t;
|
|
|
|
|
2008-08-25 02:12:02 +00:00
|
|
|
if (osdnumsymbols >= MAXSYMBOLS) return NULL;
|
2006-04-24 19:04:22 +00:00
|
|
|
newsymb = (symbol_t *)Bmalloc(sizeof(symbol_t));
|
|
|
|
if (!newsymb) { return NULL; }
|
|
|
|
Bmemset(newsymb, 0, sizeof(symbol_t));
|
|
|
|
|
|
|
|
// link it to the main chain
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!symbols)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
symbols = newsymb;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (Bstrcasecmp(name, symbols->name) <= 0)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
t = symbols;
|
|
|
|
symbols = newsymb;
|
|
|
|
symbols->next = t;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
s = symbols;
|
2007-12-12 17:42:14 +00:00
|
|
|
while (s->next)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (Bstrcasecmp(s->next->name, name) > 0) break;
|
|
|
|
s=s->next;
|
|
|
|
}
|
|
|
|
t = s->next;
|
|
|
|
s->next = newsymb;
|
|
|
|
newsymb->next = t;
|
|
|
|
}
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
hash_add(&h_osd, name, osdnumsymbols);
|
2010-05-16 22:53:08 +00:00
|
|
|
name = Bstrtolower(Bstrdup(name));
|
2010-05-02 23:27:30 +00:00
|
|
|
hash_add(&h_osd, name, osdnumsymbols);
|
|
|
|
Bfree((void *)name);
|
2008-08-25 02:12:02 +00:00
|
|
|
osdsymbptrs[osdnumsymbols++] = newsymb;
|
2006-04-24 19:04:22 +00:00
|
|
|
return newsymb;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// findsymbol() -- Finds a symbol, possibly partially named
|
2006-04-24 19:04:22 +00:00
|
|
|
//
|
2006-04-13 20:47:06 +00:00
|
|
|
static symbol_t *findsymbol(const char *name, symbol_t *startingat)
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!startingat) startingat = symbols;
|
|
|
|
if (!startingat) return NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
for (; startingat; startingat=startingat->next)
|
2010-05-02 23:27:30 +00:00
|
|
|
if (startingat->func != OSD_UNALIASED && !Bstrncasecmp(name, startingat->name, Bstrlen(name))) return startingat;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
return NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// findexactsymbol() -- Finds a symbol, complete named
|
2006-04-24 19:04:22 +00:00
|
|
|
//
|
2006-04-13 20:47:06 +00:00
|
|
|
static symbol_t *findexactsymbol(const char *name)
|
|
|
|
{
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i;
|
2008-10-18 12:37:26 +00:00
|
|
|
char *lname = Bstrdup(name);
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!symbols) return NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
i = hash_find(&h_osd,lname);
|
2008-08-25 02:33:25 +00:00
|
|
|
if (i > -1)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
// if ((symbol_t *)osdsymbptrs[i]->func == OSD_UNALIASED)
|
2008-08-25 23:48:00 +00:00
|
|
|
// return NULL;
|
2008-10-18 12:37:26 +00:00
|
|
|
Bfree(lname);
|
2008-08-25 02:33:25 +00:00
|
|
|
return osdsymbptrs[i];
|
|
|
|
}
|
2008-12-31 09:07:49 +00:00
|
|
|
|
|
|
|
// try it again
|
2010-05-16 22:53:08 +00:00
|
|
|
Bstrtolower(lname);
|
2010-05-02 23:27:30 +00:00
|
|
|
i = hash_find(&h_osd,lname);
|
2008-10-18 12:37:26 +00:00
|
|
|
Bfree(lname);
|
2008-12-31 09:07:49 +00:00
|
|
|
|
|
|
|
if (i > -1)
|
|
|
|
return osdsymbptrs[i];
|
2006-04-24 19:04:22 +00:00
|
|
|
return NULL;
|
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 showval = (parm->numparms == 0);
|
|
|
|
int32_t i;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
i = hash_find(&h_cvars, parm->name);
|
2009-04-29 06:20:07 +00:00
|
|
|
|
|
|
|
if (i < 0)
|
|
|
|
for (i = osdnumcvars-1; i >= 0; i--)
|
|
|
|
if (!Bstrcasecmp(parm->name, cvars[i].name)) break;
|
|
|
|
|
|
|
|
if (i > -1)
|
|
|
|
{
|
|
|
|
if ((cvars[i].type & CVAR_NOMULTI) && numplayers > 1)
|
|
|
|
{
|
|
|
|
// sound the alarm
|
|
|
|
OSD_Printf("Cvar \"%s\" locked in multiplayer.\n",cvars[i].name);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2009-04-30 21:09:44 +00:00
|
|
|
|
|
|
|
switch (cvars[i].type&(CVAR_FLOAT|CVAR_DOUBLE|CVAR_INT|CVAR_UINT|CVAR_BOOL|CVAR_STRING))
|
|
|
|
{
|
|
|
|
case CVAR_FLOAT:
|
2009-06-24 08:20:10 +00:00
|
|
|
{
|
|
|
|
float val;
|
|
|
|
if (showval)
|
2009-04-30 01:07:08 +00:00
|
|
|
{
|
2009-06-24 08:20:10 +00:00
|
|
|
OSD_Printf("\"%s\" is \"%f\"\n%s\n",cvars[i].name,*(float*)cvars[i].var,(char*)cvars[i].helpstr);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
sscanf(parm->parms[0], "%f", &val);
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (val < cvars[i].min || val > cvars[i].max)
|
|
|
|
{
|
|
|
|
OSD_Printf("%s value out of range\n",cvars[i].name);
|
|
|
|
return OSDCMD_OK;
|
2009-04-30 01:07:08 +00:00
|
|
|
}
|
2009-06-24 08:20:10 +00:00
|
|
|
*(float*)cvars[i].var = val;
|
|
|
|
if (!OSD_ParsingScript())
|
|
|
|
OSD_Printf("%s %f",cvars[i].name,val);
|
|
|
|
}
|
|
|
|
break;
|
2009-04-30 21:09:44 +00:00
|
|
|
case CVAR_DOUBLE:
|
2009-06-24 08:20:10 +00:00
|
|
|
{
|
|
|
|
double val;
|
|
|
|
if (showval)
|
2009-04-30 21:09:44 +00:00
|
|
|
{
|
2009-06-24 08:20:10 +00:00
|
|
|
OSD_Printf("\"%s\" is \"%f\"\n%s\n",cvars[i].name,*(double*)cvars[i].var,(char*)cvars[i].helpstr);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2009-04-30 21:09:44 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
sscanf(parm->parms[0], "%lf", &val);
|
2009-04-30 21:09:44 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (val < cvars[i].min || val > cvars[i].max)
|
|
|
|
{
|
|
|
|
OSD_Printf("%s value out of range\n",cvars[i].name);
|
|
|
|
return OSDCMD_OK;
|
2009-04-30 21:09:44 +00:00
|
|
|
}
|
2009-06-24 08:20:10 +00:00
|
|
|
*(double*)cvars[i].var = val;
|
|
|
|
if (!OSD_ParsingScript())
|
|
|
|
OSD_Printf("%s %f",cvars[i].name,val);
|
|
|
|
}
|
|
|
|
break;
|
2009-04-30 21:09:44 +00:00
|
|
|
case CVAR_INT:
|
|
|
|
case CVAR_UINT:
|
|
|
|
case CVAR_BOOL:
|
2009-06-24 08:20:10 +00:00
|
|
|
{
|
|
|
|
int32_t val;
|
|
|
|
if (showval)
|
2009-04-30 01:07:08 +00:00
|
|
|
{
|
2009-06-24 08:20:10 +00:00
|
|
|
OSD_Printf("\"%s\" is \"%d\"\n%s\n",cvars[i].name,*(int32_t*)cvars[i].var,(char*)cvars[i].helpstr);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
val = atoi(parm->parms[0]);
|
|
|
|
if (cvars[i].type & CVAR_BOOL) val = val != 0;
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (val < cvars[i].min || val > cvars[i].max)
|
|
|
|
{
|
|
|
|
OSD_Printf("%s value out of range\n",cvars[i].name);
|
|
|
|
return OSDCMD_OK;
|
2009-04-30 01:07:08 +00:00
|
|
|
}
|
2009-06-24 08:20:10 +00:00
|
|
|
*(int32_t*)cvars[i].var = val;
|
|
|
|
if (!OSD_ParsingScript())
|
|
|
|
OSD_Printf("%s %d",cvars[i].name,val);
|
|
|
|
}
|
|
|
|
break;
|
2009-04-30 21:09:44 +00:00
|
|
|
case CVAR_STRING:
|
2009-06-24 08:20:10 +00:00
|
|
|
{
|
|
|
|
if (showval)
|
2009-04-30 01:07:08 +00:00
|
|
|
{
|
2009-06-24 08:20:10 +00:00
|
|
|
OSD_Printf("\"%s\" is \"%s\"\n%s\n",cvars[i].name,(char*)cvars[i].var,(char*)cvars[i].helpstr);
|
|
|
|
return OSDCMD_OK;
|
2009-04-30 01:07:08 +00:00
|
|
|
}
|
2009-06-24 08:20:10 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
Bstrncpy((char*)cvars[i].var, parm->parms[0], cvars[i].max-1);
|
|
|
|
((char*)cvars[i].var)[cvars[i].max-1] = 0;
|
2009-06-24 08:20:10 +00:00
|
|
|
if (!OSD_ParsingScript())
|
|
|
|
OSD_Printf("%s %s",cvars[i].name,(char*)cvars[i].var);
|
|
|
|
}
|
|
|
|
break;
|
2009-04-30 21:09:44 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-04-29 06:20:07 +00:00
|
|
|
}
|
2009-04-30 21:09:44 +00:00
|
|
|
|
2009-04-29 19:43:51 +00:00
|
|
|
if (!OSD_ParsingScript())
|
|
|
|
OSD_Printf("\n");
|
2009-04-30 21:09:44 +00:00
|
|
|
|
2009-04-29 06:20:07 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2009-04-30 21:09:44 +00:00
|
|
|
void OSD_WriteCvars(FILE *fp)
|
2009-04-29 19:43:51 +00:00
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
if (!fp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i=0; i<osdnumcvars; i++)
|
2009-04-29 19:43:51 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (!(cvars[i].type & CVAR_NOSAVE))
|
|
|
|
switch (cvars[i].type&(CVAR_FLOAT|CVAR_DOUBLE|CVAR_INT|CVAR_UINT|CVAR_BOOL|CVAR_STRING))
|
2009-04-29 19:43:51 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
case CVAR_FLOAT:
|
|
|
|
fprintf(fp,"%s \"%f\"\n",cvars[i].name,*(float*)cvars[i].var);
|
|
|
|
break;
|
|
|
|
case CVAR_DOUBLE:
|
|
|
|
fprintf(fp,"%s \"%f\"\n",cvars[i].name,*(double*)cvars[i].var);
|
|
|
|
break;
|
|
|
|
case CVAR_INT:
|
|
|
|
case CVAR_UINT:
|
|
|
|
case CVAR_BOOL:
|
|
|
|
fprintf(fp,"%s \"%d\"\n",cvars[i].name,*(int32_t *)cvars[i].var);
|
|
|
|
break;
|
|
|
|
case CVAR_STRING:
|
|
|
|
fprintf(fp,"%s \"%s\"\n",cvars[i].name,(char*)cvars[i].var);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-04-29 19:43:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|