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
|
|
|
|
|
|
|
#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"
|
2017-06-14 07:00:02 +00:00
|
|
|
#define XXH_STATIC_LINKING_ONLY
|
2014-03-22 09:26:39 +00:00
|
|
|
#include "xxhash.h"
|
2014-10-25 03:29:53 +00:00
|
|
|
#include "common.h"
|
2015-01-11 04:52:15 +00:00
|
|
|
#include "editor.h"
|
2013-12-24 09:44:24 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static osdsymbol_t *symbols = NULL;
|
|
|
|
static osdsymbol_t *osd_addsymbol(const char *name);
|
|
|
|
static osdsymbol_t *osd_findsymbol(const char *pszName, osdsymbol_t *pSymbol);
|
|
|
|
static osdsymbol_t *osd_findexactsymbol(const char *pszName);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
// static int32_t _validate_osdlines(void *);
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_listsymbols(osdfuncparm_t const * const);
|
|
|
|
static int32_t osdfunc_help(osdfuncparm_t const * const);
|
|
|
|
static int32_t osdfunc_alias(osdfuncparm_t const * const);
|
|
|
|
// static int32_t osdfunc_dumpbuildinfo(osdfuncparm_t const * const);
|
|
|
|
// static int32_t osdfunc_setrendermode(osdfuncparm_t const * const);
|
2009-01-09 09:29:17 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t whiteColorIdx=-1; // colour of white (used by default display routines)
|
2009-01-09 09:29:17 +00:00
|
|
|
static void _internal_drawosdchar(int32_t, int32_t, char, int32_t, int32_t);
|
2012-12-25 16:13:50 +00:00
|
|
|
static void _internal_drawosdstr(int32_t, int32_t, const char *, int32_t, int32_t, int32_t);
|
2009-01-09 09:29:17 +00:00
|
|
|
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
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
osdmain_t *osd = NULL;
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static int32_t osdrowscur=-1;
|
|
|
|
static int32_t osdmaxrows=20; // maximum number of lines which can fit on the screen
|
2014-12-17 13:02:21 +00:00
|
|
|
BFILE *osdlog; // log filehandle
|
|
|
|
const char* osdlogfn;
|
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
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
|
|
|
|
#define editlinewidth (osd->draw.cols-1-3)
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static hashtable_t h_osd = { OSDMAXSYMBOLS << 1, NULL };
|
2008-08-25 02:12:02 +00:00
|
|
|
|
2013-11-04 22:56:12 +00:00
|
|
|
// Application callbacks: these are the currently effective ones.
|
2009-01-09 09:29:17 +00:00
|
|
|
static void (*drawosdchar)(int32_t, int32_t, char, int32_t, int32_t) = _internal_drawosdchar;
|
2012-12-25 16:13:50 +00:00
|
|
|
static void (*drawosdstr)(int32_t, int32_t, const char *, int32_t, int32_t, int32_t) = _internal_drawosdstr;
|
2009-01-09 09:29:17 +00:00
|
|
|
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;
|
2013-11-04 22:56:12 +00:00
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
static void (*clearbackground)(int32_t,int32_t) = _internal_clearbackground;
|
|
|
|
static int32_t (*gettime)(void) = _internal_gettime;
|
|
|
|
static void (*onshowosd)(int32_t) = _internal_onshowosd;
|
|
|
|
|
2013-11-04 22:56:12 +00:00
|
|
|
// Application callbacks: these are the backed-up ones.
|
2009-01-09 09:29:17 +00:00
|
|
|
static void (*_drawosdchar)(int32_t, int32_t, char, int32_t, int32_t) = _internal_drawosdchar;
|
2012-12-25 16:13:50 +00:00
|
|
|
static void (*_drawosdstr)(int32_t, int32_t, const char *, int32_t, int32_t, int32_t) = _internal_drawosdstr;
|
2009-01-09 09:29:17 +00:00
|
|
|
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
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
static hashtable_t h_cvars = { OSDMAXSYMBOLS<<1, NULL };
|
2010-05-22 23:41:18 +00:00
|
|
|
int32_t m32_osd_tryscript=0; // whether to try executing m32script on unkown command in the osd
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
void OSD_RegisterCvar(osdcvardata_t * const cvar, int32_t (*func)(osdfuncparm_t const * const))
|
2009-04-29 06:20:07 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
if (!osd)
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_Init();
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->cvars = (osdcvar_t *)Xrealloc(osd->cvars, (osd->numcvars + 1) * sizeof(osdcvar_t));
|
2010-06-07 09:03:16 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
hash_add(&h_cvars, cvar->name, osd->numcvars, 1);
|
2010-06-07 09:03:16 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
switch (cvar->flags & CVAR_TYPEMASK)
|
2010-06-07 09:03:16 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
case CVAR_FLOAT:
|
|
|
|
#if defined __POWERPC__ || defined GEKKO
|
|
|
|
osd->cvars[osd->numcvars].defaultValue.f = *cvar->f;
|
|
|
|
break;
|
|
|
|
#endif
|
2010-06-07 09:03:16 +00:00
|
|
|
case CVAR_BOOL:
|
|
|
|
case CVAR_INT:
|
|
|
|
case CVAR_UINT:
|
2017-06-27 02:24:14 +00:00
|
|
|
osd->cvars[osd->numcvars].defaultValue.u32 = *cvar->u32;
|
2010-06-07 09:03:16 +00:00
|
|
|
break;
|
|
|
|
case CVAR_DOUBLE:
|
2017-06-27 02:24:14 +00:00
|
|
|
osd->cvars[osd->numcvars].defaultValue.d = *cvar->d;
|
2010-06-07 09:03:16 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
osd->cvars[osd->numcvars++].pData = cvar;
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_RegisterFunction(cvar->name, cvar->desc, func);
|
2009-04-29 06:20:07 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int OSD_CvarModified(const osdcvar_t * const pCvar)
|
2010-06-07 09:03:16 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (!osd || !pCvar->pData->ptr)
|
2010-06-07 09:03:16 +00:00
|
|
|
return 0;
|
|
|
|
|
2016-12-04 22:53:51 +00:00
|
|
|
int rv = 0;
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
switch (pCvar->pData->flags & CVAR_TYPEMASK)
|
2016-12-04 22:53:51 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
case CVAR_FLOAT:
|
|
|
|
#if defined __POWERPC__ || defined GEKKO
|
|
|
|
rv = (pCvar->defaultValue.f != *pCvar->pData->f); break;
|
|
|
|
#endif
|
2016-12-04 22:53:51 +00:00
|
|
|
case CVAR_BOOL:
|
|
|
|
case CVAR_INT:
|
|
|
|
case CVAR_UINT:
|
2017-06-27 02:24:14 +00:00
|
|
|
rv = (pCvar->defaultValue.u32 != *pCvar->pData->u32); break;
|
2016-12-04 22:53:51 +00:00
|
|
|
case CVAR_DOUBLE:
|
2017-06-27 02:24:14 +00:00
|
|
|
rv = (pCvar->defaultValue.d != *pCvar->pData->d); break;
|
2016-12-04 22:53:51 +00:00
|
|
|
case CVAR_STRING:
|
|
|
|
rv = 1; break;
|
|
|
|
default:
|
|
|
|
EDUKE32_UNREACHABLE_SECTION(break);
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
return rv || ((pCvar->pData->flags & CVAR_MODIFIED) == CVAR_MODIFIED);
|
2010-06-07 09:03:16 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
const char * OSD_StripColors(char *outBuf, const char *inBuf)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
const char *ptr = outBuf;
|
2008-06-30 07:30:48 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
while (*inBuf)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (*inBuf == '^')
|
2008-07-19 07:39:51 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (isdigit(*(inBuf+1)))
|
|
|
|
inBuf += 2 + !!isdigit(*(inBuf+2));
|
|
|
|
else if ((Btoupper(*(inBuf+1)) == 'O'))
|
|
|
|
inBuf += 2;
|
|
|
|
else if ((Btoupper(*(inBuf+1)) == 'S') && isdigit(*(inBuf+2)))
|
|
|
|
inBuf += 3;
|
|
|
|
|
2008-07-19 00:50:20 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
*(outBuf++) = *(inBuf++);
|
2008-08-24 06:17:09 +00:00
|
|
|
}
|
2008-08-24 05:39:28 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
*outBuf = '\0';
|
2013-05-04 16:36:13 +00:00
|
|
|
return ptr;
|
2008-06-30 07:30:48 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
int OSD_Exec(const char *szScript)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int err = 0;
|
|
|
|
int32_t handle, len;
|
2015-07-08 03:34:37 +00:00
|
|
|
char *buf = NULL;
|
2014-10-25 03:29:53 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if ((handle = kopen4load(szScript, 0)) == -1)
|
2016-01-12 10:31:19 +00:00
|
|
|
err = 1;
|
2017-06-27 02:24:14 +00:00
|
|
|
else if ((len = kfilelength(handle)) <= 0)
|
2016-01-12 10:31:19 +00:00
|
|
|
err = 2; // blank file
|
2017-06-27 02:24:14 +00:00
|
|
|
else if ((buf = (char *) Xmalloc(len + 1)) == NULL)
|
2016-01-12 10:31:19 +00:00
|
|
|
err = 3;
|
2008-06-30 07:30:48 +00:00
|
|
|
|
2014-10-25 03:35:05 +00:00
|
|
|
if (!err || err == 3)
|
|
|
|
OSD_Printf("Executing \"%s\"\n", szScript);
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (err || kread(handle, buf, len) != len)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2014-10-25 03:35:05 +00:00
|
|
|
if (!err || err == 3) // no error message for blank file
|
2014-10-25 03:29:53 +00:00
|
|
|
OSD_Printf("Error executing \"%s\"!\n", szScript);
|
2017-06-27 02:24:14 +00:00
|
|
|
if (handle != -1) kclose(handle);
|
2015-09-23 17:55:31 +00:00
|
|
|
Bfree(buf);
|
2014-10-25 03:29:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-06-30 07:30:48 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
buf[len] = 0;
|
2014-10-25 03:29:53 +00:00
|
|
|
osd->execdepth++;
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
char const *cp = strtok(buf, "\r\n");
|
2014-10-25 03:29:53 +00:00
|
|
|
|
|
|
|
while (cp != NULL)
|
|
|
|
{
|
|
|
|
OSD_Dispatch(cp);
|
|
|
|
cp = strtok(NULL, "\r\n");
|
2008-06-30 07:30:48 +00:00
|
|
|
}
|
2014-10-25 03:29:53 +00:00
|
|
|
|
|
|
|
osd->execdepth--;
|
2017-06-27 02:24:14 +00:00
|
|
|
kclose(handle);
|
2014-10-25 03:29:53 +00:00
|
|
|
Bfree(buf);
|
|
|
|
return 0;
|
2008-06-30 07:30:48 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t OSD_ParsingScript(void) { return osd->execdepth; }
|
|
|
|
int32_t OSD_OSDKey(void) { return osd->keycode; }
|
|
|
|
int32_t OSD_GetCols(void) { return osd->draw.cols; }
|
|
|
|
int32_t OSD_IsMoving(void) { return (osdrowscur != -1 && osdrowscur != osd->draw.rows); }
|
|
|
|
int32_t OSD_GetRowsCur(void) { return osdrowscur; }
|
|
|
|
int32_t OSD_GetTextMode(void) { return osd->draw.mode; }
|
2008-07-23 03:56:50 +00:00
|
|
|
|
2013-11-04 22:56:08 +00:00
|
|
|
void OSD_GetShadePal(const char *ch, int32_t *shadeptr, int32_t *palptr)
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (ch < osd->text.buf || ch >= osd->text.buf + OSDBUFFERSIZE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*shadeptr = (osd->text.fmt[ch - osd->text.buf] & ~0x1F) >> 4;
|
|
|
|
*palptr = osd->text.fmt[ch - osd->text.buf] & ~0xE0;
|
2013-11-04 22:56:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-04 22:56:12 +00:00
|
|
|
// XXX: well, converting function pointers to "data pointers" (void *) is
|
|
|
|
// undefined behavior. See
|
|
|
|
// http://blog.frama-c.com/index.php?post/2013/08/24/Function-pointers-in-C
|
|
|
|
// Then again, my GCC just crashed (any kept on crashing until after a reboot!)
|
|
|
|
// when I tried to rewrite this into something different.
|
2012-12-25 16:13:50 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
static inline void swaposdptrs(void)
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
swapptr(&_drawosdchar, &drawosdchar);
|
|
|
|
swapptr(&_drawosdstr, &drawosdstr);
|
|
|
|
swapptr(&_drawosdcursor, &drawosdcursor);
|
2014-07-06 00:12:25 +00:00
|
|
|
swapptr(&_getcolumnwidth, &getcolumnwidth);
|
2017-06-27 02:24:14 +00:00
|
|
|
swapptr(&_getrowheight, &getrowheight);
|
2014-07-06 00:12:25 +00:00
|
|
|
}
|
|
|
|
|
2009-01-09 09:29:17 +00:00
|
|
|
void OSD_SetTextMode(int32_t mode)
|
2008-07-23 03:56:50 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->draw.mode = (mode != 0);
|
2013-05-30 09:13:32 +00:00
|
|
|
|
2015-07-08 03:34:37 +00:00
|
|
|
if ((osd->draw.mode && drawosdchar != _internal_drawosdchar) ||
|
|
|
|
(!osd->draw.mode && drawosdchar == _internal_drawosdchar))
|
2014-07-06 00:12:25 +00:00
|
|
|
swaposdptrs();
|
2013-05-30 09:13:32 +00:00
|
|
|
|
|
|
|
if (in3dmode())
|
2008-07-23 03:56:50 +00:00
|
|
|
OSD_ResizeDisplay(xdim, ydim);
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_exec(osdfuncparm_t const * const parm)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2015-07-08 03:34:37 +00:00
|
|
|
if (parm->numparms != 1)
|
|
|
|
return OSDCMD_SHOWHELP;
|
|
|
|
|
2008-06-30 07:30:48 +00:00
|
|
|
char fn[BMAX_PATH];
|
|
|
|
|
|
|
|
Bstrcpy(fn,parm->parms[0]);
|
|
|
|
|
|
|
|
if (OSD_Exec(fn))
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%sexec: file \"%s\" not found.\n", osd->draw.errorfmt, fn);
|
2015-07-08 03:34:37 +00:00
|
|
|
|
2008-06-30 07:30:48 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_echo(osdfuncparm_t const * const parm)
|
2010-05-09 22:12:29 +00:00
|
|
|
{
|
2014-10-25 03:29:53 +00:00
|
|
|
OSD_Printf("%s\n", parm->raw + 5);
|
2010-05-09 22:12:29 +00:00
|
|
|
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_fileinfo(osdfuncparm_t const * const parm)
|
2010-05-09 22:12:29 +00:00
|
|
|
{
|
|
|
|
int32_t i,j;
|
|
|
|
|
|
|
|
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
|
|
|
|
|
2016-01-11 05:05:38 +00:00
|
|
|
if ((i = kopen4load(parm->parms[0],0)) < 0)
|
2010-05-09 22:12:29 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("fileinfo: File \"%s\" not found.\n", parm->parms[0]);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-08 03:34:37 +00:00
|
|
|
char buf[256];
|
|
|
|
uint32_t length = kfilelength(i);
|
|
|
|
int32_t crctime = getticks();
|
|
|
|
uint32_t crc = 0;
|
2010-05-09 22:12:29 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
j = kread(i,buf,256);
|
2014-10-01 17:09:54 +00:00
|
|
|
crc = Bcrc32((uint8_t *)buf,j,crc);
|
2010-05-09 22:12:29 +00:00
|
|
|
}
|
|
|
|
while (j == 256);
|
2014-03-22 09:26:39 +00:00
|
|
|
crctime = getticks() - crctime;
|
|
|
|
|
|
|
|
klseek(i, 0, BSEEK_SET);
|
|
|
|
|
2015-07-08 03:34:37 +00:00
|
|
|
int32_t xxhtime = getticks();
|
2017-06-14 07:00:02 +00:00
|
|
|
XXH32_state_t xxh;
|
|
|
|
XXH32_reset(&xxh, 0x1337);
|
2014-03-22 09:26:39 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
j = kread(i, buf, 256);
|
2017-06-14 07:00:02 +00:00
|
|
|
XXH32_update(&xxh, (uint8_t *) buf, j);
|
2014-03-22 09:26:39 +00:00
|
|
|
}
|
|
|
|
while (j == 256);
|
2017-06-14 07:00:02 +00:00
|
|
|
uint32_t xxhash = XXH32_digest(&xxh);
|
2014-03-22 09:26:39 +00:00
|
|
|
xxhtime = getticks() - xxhtime;
|
2010-05-09 22:12:29 +00:00
|
|
|
|
|
|
|
kclose(i);
|
|
|
|
|
|
|
|
OSD_Printf("fileinfo: %s\n"
|
2011-01-16 02:50:27 +00:00
|
|
|
" File size: %d\n"
|
2014-03-22 09:26:39 +00:00
|
|
|
" CRC-32: %08X (%g sec)\n"
|
|
|
|
" xxHash: %08X (%g sec)\n",
|
|
|
|
parm->parms[0], length,
|
|
|
|
crc, (double)crctime/gettimerfreq(),
|
|
|
|
xxhash, (double)xxhtime/gettimerfreq());
|
2010-05-09 22:12:29 +00:00
|
|
|
|
|
|
|
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
|
|
|
{
|
2008-03-23 00:06:42 +00:00
|
|
|
UNREFERENCED_PARAMETER(shade);
|
|
|
|
UNREFERENCED_PARAMETER(pal);
|
|
|
|
|
2015-07-08 03:34:37 +00:00
|
|
|
char st[2] = { ch, 0 };
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
printext256(4+(x<<3),4+(y<<3), whiteColorIdx, -1, st, 0);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2012-12-25 16:13:50 +00:00
|
|
|
static void _internal_drawosdstr(int32_t x, int32_t y, const 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);
|
|
|
|
|
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;
|
|
|
|
|
2013-11-04 22:56:09 +00:00
|
|
|
OSD_GetShadePal(ch, &shade, &pal);
|
|
|
|
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t colidx = whiteColorIdx >= 0 ? palookup[(uint8_t)pal][whiteColorIdx] : whiteColorIdx;
|
2013-11-04 22:56:09 +00:00
|
|
|
printext256(4+(x<<3),4+(y<<3), colidx, -1, st, 0);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static void _internal_drawosdcursor(int32_t x, int32_t y, int32_t flags, 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);
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (flags) st[0] = '#';
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (whiteColorIdx > -1)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
printext256(4+(x<<3),4+(y<<3)+2, whiteColorIdx, -1, st, 0);
|
2010-05-02 23:27:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t i, k;
|
|
|
|
// Find the palette index closest to Duke3D's brightest blue
|
|
|
|
// "foreground" color. (Index 79, or the last column of the 5th row,
|
|
|
|
// if the palette is laid out in a 16x16 pattern.)
|
|
|
|
k = INT32_MAX;
|
|
|
|
for (i=0; i<256; i++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t j =
|
|
|
|
klabs(curpalette[i].r - 4*47) +
|
|
|
|
klabs(curpalette[i].g - 4*55) +
|
|
|
|
klabs(curpalette[i].b - 4*63);
|
|
|
|
if (j < k) { k = j; whiteColorIdx = i; }
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_alias(osdfuncparm_t const * const parm)
|
2008-06-29 22:37:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdsymbol_t *i;
|
2008-06-29 22:37:30 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2011-04-07 01:16:29 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
OSD_RegisterFunction(Xstrdup(parm->parms[0]), Xstrdup(parm->parms[1]), OSD_ALIAS);
|
2014-07-06 00:12:25 +00:00
|
|
|
|
|
|
|
if (!osd->execdepth)
|
2008-06-30 07:30:48 +00:00
|
|
|
OSD_Printf("%s\n",parm->raw);
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2008-06-29 22:37:30 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_unalias(osdfuncparm_t const * const parm)
|
2008-06-30 01:03:51 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdsymbol_t *i;
|
2008-06-30 01:03:51 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_listsymbols(osdfuncparm_t const * const parm)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdsymbol_t *i;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t maxwidth = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2013-08-06 23:53:12 +00:00
|
|
|
if (parm->numparms > 1)
|
|
|
|
return OSDCMD_SHOWHELP;
|
2008-03-23 00:06:42 +00:00
|
|
|
|
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;
|
2013-08-06 23:53:12 +00:00
|
|
|
|
|
|
|
if (parm->numparms > 0)
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%sSymbol listing for %s:\n", osd->draw.highlight, parm->parms[0]);
|
2013-08-06 23:53:12 +00:00
|
|
|
else
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%sSymbol listing:\n", osd->draw.highlight);
|
2013-08-06 23:53:12 +00:00
|
|
|
|
2008-06-30 07:30:48 +00:00
|
|
|
for (i=symbols; i!=NULL; i=i->next)
|
|
|
|
{
|
2013-08-06 23:53:12 +00:00
|
|
|
if (i->func == OSD_UNALIASED || (parm->numparms == 1 && Bstrncmp(parm->parms[0], i->name, Bstrlen(parm->parms[0]))))
|
2011-04-07 01:16:29 +00:00
|
|
|
continue;
|
|
|
|
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2010-06-07 09:03:16 +00:00
|
|
|
int32_t j = hash_find(&h_cvars, i->name);
|
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (j != -1 && OSD_CvarModified(&osd->cvars[j]))
|
2010-06-07 09:03:16 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%s*", osd->draw.highlight);
|
2010-06-07 09:03:16 +00:00
|
|
|
OSD_Printf("%-*s",maxwidth-1,i->name);
|
|
|
|
}
|
|
|
|
else OSD_Printf("%-*s",maxwidth,i->name);
|
|
|
|
|
2008-06-30 07:30:48 +00:00
|
|
|
x += maxwidth;
|
2008-07-30 05:41:03 +00:00
|
|
|
count++;
|
2008-06-30 07:30:48 +00:00
|
|
|
}
|
2011-04-07 01:16:29 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (x > osd->draw.cols - maxwidth)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
OSD_Printf("\n");
|
|
|
|
}
|
|
|
|
}
|
2008-07-30 05:41:03 +00:00
|
|
|
if (x) OSD_Printf("\n");
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%sFound %d symbols\n", osd->draw.highlight, 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
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_help(osdfuncparm_t const * const parm)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdsymbol_t *symb;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (parm->numparms != 1)
|
|
|
|
return OSDCMD_SHOWHELP;
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
symb = osd_findexactsymbol(parm->parms[0]);
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!symb)
|
2011-01-16 02:50:27 +00:00
|
|
|
OSD_Printf("Error: no help for undefined symbol \"%s\"\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
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_clear(osdfuncparm_t const * const UNUSED(parm))
|
2007-01-04 07:15:17 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
osdtext_t *t = &osd->text;
|
2017-06-27 02:24:14 +00:00
|
|
|
UNREFERENCED_CONST_PARAMETER(parm);
|
2014-07-06 00:12:25 +00:00
|
|
|
|
|
|
|
Bmemset(t->buf, 0, OSDBUFFERSIZE);
|
|
|
|
Bmemset(t->fmt, osd->draw.textpal + (osd->draw.textshade<<5), OSDBUFFERSIZE);
|
|
|
|
t->lines = 1;
|
|
|
|
|
2007-01-04 07:15:17 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_history(osdfuncparm_t const * const UNUSED(parm))
|
2008-07-07 12:17:27 +00:00
|
|
|
{
|
2015-07-08 03:34:37 +00:00
|
|
|
int32_t j = 0;
|
2014-07-06 00:12:25 +00:00
|
|
|
osdhist_t *h = &osd->history;
|
2017-06-27 02:24:14 +00:00
|
|
|
UNREFERENCED_CONST_PARAMETER(parm);
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%sCommand history:\n", osd->draw.highlight);
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=osd->history.maxlines-1; i>=0; i--)
|
2014-07-06 00:12:25 +00:00
|
|
|
if (h->buf[i])
|
|
|
|
OSD_Printf("%4d \"%s\"\n", h->total - h->lines + (++j), h->buf[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)
|
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
hash_free(&h_osd);
|
|
|
|
hash_free(&h_cvars);
|
2008-08-25 02:12:02 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
for (osdsymbol_t *s; symbols; symbols=s)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
s=symbols->next;
|
|
|
|
Bfree(symbols);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
MAYBE_FCLOSE_AND_NULL(osdlog);
|
|
|
|
DO_FREE_AND_NULL(osd->cvars);
|
|
|
|
DO_FREE_AND_NULL(osd->editor.buf);
|
2015-05-25 12:57:49 +00:00
|
|
|
DO_FREE_AND_NULL(osd->editor.tmp);
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i=0; i<OSDMAXHISTORYDEPTH; i++)
|
2014-07-06 00:12:25 +00:00
|
|
|
DO_FREE_AND_NULL(osd->history.buf[i]);
|
|
|
|
DO_FREE_AND_NULL(osd->text.buf);
|
|
|
|
DO_FREE_AND_NULL(osd->text.fmt);
|
|
|
|
DO_FREE_AND_NULL(osd);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdcmd_cvar_set_osd(osdfuncparm_t const * const parm)
|
2009-04-30 01:07:08 +00:00
|
|
|
{
|
|
|
|
int32_t r = osdcmd_cvar_set(parm);
|
|
|
|
|
2015-07-08 03:34:37 +00:00
|
|
|
if (r != OSDCMD_OK)
|
|
|
|
return r;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2015-07-08 03:34:37 +00:00
|
|
|
if (!Bstrcasecmp(parm->name, "osdrows"))
|
|
|
|
{
|
|
|
|
if (osd->draw.rows > osdmaxrows)
|
|
|
|
osd->draw.rows = osdmaxrows;
|
|
|
|
if (osdrowscur != -1)
|
|
|
|
osdrowscur = osd->draw.rows;
|
|
|
|
}
|
|
|
|
else if (!Bstrcasecmp(parm->name, "osdtextmode"))
|
|
|
|
OSD_SetTextMode(osd->draw.mode);
|
|
|
|
else if (!Bstrcasecmp(parm->name, "osdhistorydepth"))
|
|
|
|
{
|
2016-08-27 01:41:21 +00:00
|
|
|
for (bssize_t i = OSDMAXHISTORYDEPTH - 1; i >= osd->history.maxlines; i--)
|
2015-07-08 03:34:37 +00:00
|
|
|
DO_FREE_AND_NULL(osd->history.buf[i]);
|
2009-04-30 01:07:08 +00:00
|
|
|
}
|
2015-07-08 03:34:37 +00:00
|
|
|
|
|
|
|
return OSDCMD_OK;
|
2009-04-30 01:07:08 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static int32_t osdfunc_toggle(osdfuncparm_t const * const parm)
|
2010-06-07 09:03:16 +00:00
|
|
|
{
|
|
|
|
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
|
|
|
|
|
2015-07-08 03:34:37 +00:00
|
|
|
intptr_t i = hash_find(&h_cvars, parm->parms[0]);
|
2010-06-07 09:03:16 +00:00
|
|
|
|
|
|
|
if (i == -1)
|
2014-07-06 00:12:25 +00:00
|
|
|
for (i = osd->numcvars-1; i >= 0; i--)
|
2017-06-27 02:24:14 +00:00
|
|
|
if (!Bstrcasecmp(parm->parms[0], osd->cvars[i].pData->name)) break;
|
2010-06-07 09:03:16 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (i == -1 || (osd->cvars[i].pData->flags & CVAR_TYPEMASK) != CVAR_BOOL)
|
2010-06-07 09:03:16 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("Bad cvar name or cvar not boolean\n");
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
*osd->cvars[i].pData->i32 = 1 - *osd->cvars[i].pData->i32;
|
|
|
|
osd->cvars[i].pData->flags |= CVAR_MODIFIED;
|
2016-12-01 04:06:40 +00:00
|
|
|
|
2010-06-07 09:03:16 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
osd = (osdmain_t *)Bcalloc(1, sizeof(osdmain_t));
|
|
|
|
|
|
|
|
mutex_init(&osd->mutex);
|
|
|
|
|
|
|
|
if (!osd->keycode) osd->keycode = sc_Tilde;
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
osd->text.buf = (char *)Bmalloc(OSDBUFFERSIZE);
|
|
|
|
osd->text.fmt = (char *)Bmalloc(OSDBUFFERSIZE);
|
|
|
|
osd->editor.buf = (char *)Bmalloc(OSDEDITLENGTH);
|
|
|
|
osd->editor.tmp = (char *)Bmalloc(OSDEDITLENGTH);
|
2014-07-06 00:12:25 +00:00
|
|
|
|
|
|
|
Bmemset(osd->text.buf, asc_Space, OSDBUFFERSIZE);
|
|
|
|
Bmemset(osd->text.fmt, osd->draw.textpal + (osd->draw.textshade<<5), OSDBUFFERSIZE);
|
|
|
|
Bmemset(osd->symbptrs, 0, sizeof(osd->symbptrs));
|
|
|
|
|
|
|
|
osd->numsymbols = osd->numcvars = 0;
|
|
|
|
osd->text.lines = 1;
|
|
|
|
osd->text.maxlines = OSDDEFAULTMAXLINES; // overwritten later
|
|
|
|
osd->draw.rows = OSDDEFAULTROWS;
|
|
|
|
osd->draw.cols = OSDDEFAULTCOLS;
|
|
|
|
osd->log.cutoff = OSDLOGCUTOFF;
|
|
|
|
osd->history.maxlines = OSDMINHISTORYDEPTH;
|
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
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static osdcvardata_t cvars_osd [] =
|
2009-04-30 01:07:08 +00:00
|
|
|
{
|
2015-07-08 03:34:37 +00:00
|
|
|
{ "osdeditpal", "sets the palette of the OSD input text", (void *) &osd->draw.editpal, CVAR_INT, 0, MAXPALOOKUPS-1 },
|
|
|
|
{ "osdpromptpal", "sets the palette of the OSD prompt", (void *) &osd->draw.promptpal, CVAR_INT, 0, MAXPALOOKUPS-1 },
|
|
|
|
{ "osdtextpal", "sets the palette of the OSD text", (void *) &osd->draw.textpal, CVAR_INT, 0, MAXPALOOKUPS-1 },
|
|
|
|
{ "osdeditshade", "sets the shade of the OSD input text", (void *) &osd->draw.editshade, CVAR_INT, 0, 7 },
|
|
|
|
{ "osdtextshade", "sets the shade of the OSD text", (void *) &osd->draw.textshade, CVAR_INT, 0, 7 },
|
|
|
|
{ "osdpromptshade", "sets the shade of the OSD prompt", (void *) &osd->draw.promptshade, CVAR_INT, INT8_MIN, INT8_MAX },
|
2016-01-27 07:30:18 +00:00
|
|
|
{ "osdrows", "sets the number of visible lines of the OSD", (void *) &osd->draw.rows, CVAR_INT|CVAR_FUNCPTR, 1, 400 },
|
2015-07-08 03:34:37 +00:00
|
|
|
{ "osdtextmode", "set OSD text mode (0:graphical, 1:fast)", (void *) &osd->draw.mode, CVAR_BOOL|CVAR_FUNCPTR, 0, 1 },
|
|
|
|
{ "osdlogcutoff", "sets the maximal line count of the log file", (void *) &osd->log.cutoff, CVAR_INT, 0, 262144 },
|
|
|
|
{ "osdhistorydepth", "sets the history depth, in lines", (void *) &osd->history.maxlines, CVAR_INT|CVAR_FUNCPTR, OSDMINHISTORYDEPTH, OSDMAXHISTORYDEPTH },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (unsigned i=0; i<ARRAY_SIZE(cvars_osd); i++)
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_RegisterCvar(&cvars_osd[i], cvars_osd[i].flags & CVAR_FUNCPTR ? osdcmd_cvar_set_osd : osdcmd_cvar_set);
|
|
|
|
|
|
|
|
OSD_RegisterFunction("alias", "alias: creates an alias for calling multiple commands", osdfunc_alias);
|
|
|
|
OSD_RegisterFunction("clear", "clear: clears the console text buffer", osdfunc_clear);
|
|
|
|
OSD_RegisterFunction("echo", "echo [text]: echoes text to the console", osdfunc_echo);
|
|
|
|
OSD_RegisterFunction("exec", "exec <scriptfile>: executes a script", osdfunc_exec);
|
|
|
|
OSD_RegisterFunction("fileinfo", "fileinfo <file>: gets a file's information", osdfunc_fileinfo);
|
|
|
|
OSD_RegisterFunction("help", "help: displays help for a cvar or command; \"listsymbols\" to show all commands", osdfunc_help);
|
|
|
|
OSD_RegisterFunction("history", "history: displays the console command history", osdfunc_history);
|
|
|
|
OSD_RegisterFunction("listsymbols", "listsymbols: lists all registered functions, cvars and aliases", osdfunc_listsymbols);
|
|
|
|
OSD_RegisterFunction("toggle", "toggle: toggles the value of a boolean cvar", osdfunc_toggle);
|
|
|
|
OSD_RegisterFunction("unalias", "unalias: removes a command alias", osdfunc_unalias);
|
|
|
|
|
|
|
|
// atexit(OSD_Cleanup);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_SetLogFile() -- Sets the text file where printed text should be echoed
|
|
|
|
//
|
2012-07-01 22:11:33 +00:00
|
|
|
void OSD_SetLogFile(const char *fn)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-11-02 05:36:05 +00:00
|
|
|
MAYBE_FCLOSE_AND_NULL(osdlog);
|
2014-12-17 13:02:21 +00:00
|
|
|
osdlogfn = NULL;
|
2014-11-02 05:36:05 +00:00
|
|
|
|
|
|
|
if (!fn)
|
|
|
|
return;
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2014-11-02 05:36:05 +00:00
|
|
|
osdlog = Bfopen(fn, "w");
|
2014-10-25 03:29:53 +00:00
|
|
|
|
|
|
|
if (osdlog)
|
2014-12-17 13:02:21 +00:00
|
|
|
{
|
2015-07-08 03:34:37 +00:00
|
|
|
#ifdef DEBUGGINGAIDS
|
|
|
|
const int bufmode = _IONBF;
|
|
|
|
#else
|
|
|
|
const int bufmode = _IOLBF;
|
|
|
|
#endif
|
2014-11-02 05:36:05 +00:00
|
|
|
setvbuf(osdlog, (char *)NULL, bufmode, BUFSIZ);
|
2014-12-17 13:02:21 +00:00
|
|
|
osdlogfn = fn;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_SetFunctions() -- Sets some callbacks which the OSD uses to understand its world
|
|
|
|
//
|
2017-06-27 02:24:14 +00:00
|
|
|
void OSD_SetFunctions(void (*drawchar)(int32_t, int32_t, char, int32_t, int32_t),
|
|
|
|
void (*drawstr)(int32_t, int32_t, const 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-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
drawosdchar = drawchar ? drawchar : _internal_drawosdchar;
|
|
|
|
drawosdstr = drawstr ? drawstr : _internal_drawosdstr;
|
|
|
|
drawosdcursor = drawcursor ? drawcursor : _internal_drawosdcursor;
|
|
|
|
getcolumnwidth = colwidth ? colwidth : _internal_getcolumnwidth;
|
|
|
|
getrowheight = rowheight ? rowheight : _internal_getrowheight;
|
|
|
|
clearbackground = clearbg ? clearbg : _internal_clearbackground;
|
|
|
|
gettime = gtime ? gtime : _internal_gettime;
|
|
|
|
onshowosd = showosd ? showosd : _internal_onshowosd;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_SetParameters() -- Sets the parameters for presenting the text
|
|
|
|
//
|
2017-06-27 02:24:14 +00:00
|
|
|
void OSD_SetParameters(int32_t promptShade, int32_t promptPal, int32_t editShade, int32_t editPal, int32_t textShade, int32_t textPal,
|
2017-07-05 05:42:37 +00:00
|
|
|
char const *const errorStr, char const *const highlight, uint32_t flags)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osddraw_t &draw = osd->draw;
|
|
|
|
|
|
|
|
draw.promptshade = promptShade;
|
|
|
|
draw.promptpal = promptPal;
|
|
|
|
draw.editshade = editShade;
|
|
|
|
draw.editpal = editPal;
|
|
|
|
draw.textshade = textShade;
|
|
|
|
draw.textpal = textPal;
|
|
|
|
draw.errorfmt = errorStr;
|
|
|
|
draw.highlight = highlight;
|
2017-07-05 05:42:37 +00:00
|
|
|
|
|
|
|
osd->flags |= flags;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_CaptureKey() -- Sets the scancode for the key which activates the onscreen display
|
|
|
|
//
|
2017-06-27 02:24:14 +00:00
|
|
|
void OSD_CaptureKey(uint8_t scanCode)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osd->keycode = scanCode;
|
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)
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdhist_t &history = osd->history;
|
|
|
|
|
|
|
|
if (history.pos >= history.lines-1) return;
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
osdedit_t &editor = osd->editor;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
Bmemcpy(editor.buf, history.buf[++history.pos], OSDEDITLENGTH);
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.pos = 0;
|
|
|
|
while (editor.buf[editor.pos]) editor.pos++;
|
|
|
|
editor.len = editor.pos;
|
|
|
|
|
|
|
|
if (editor.pos < editor.start)
|
2008-07-08 04:52:39 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.end = editor.pos;
|
|
|
|
editor.start = editor.end - editlinewidth;
|
2008-07-08 04:52:39 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.start < 0)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.end -= editor.start;
|
|
|
|
editor.start = 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
else if (editor.pos >= editor.end)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.start += (editor.pos - editor.end);
|
|
|
|
editor.end += (editor.pos - editor.end);
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void OSD_HistoryNext(void)
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdhist_t &history = osd->history;
|
|
|
|
|
|
|
|
if (history.pos < 0) return;
|
|
|
|
|
|
|
|
osdedit_t &editor = osd->editor;
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (history.pos == 0)
|
2008-07-08 04:52:39 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.len = 0;
|
|
|
|
editor.pos = 0;
|
|
|
|
editor.start = 0;
|
|
|
|
editor.end = editlinewidth;
|
|
|
|
history.pos = -1;
|
2008-07-09 09:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
Bmemcpy(editor.buf, history.buf[--history.pos], OSDEDITLENGTH);
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.pos = 0;
|
|
|
|
while (editor.buf[editor.pos]) editor.pos++;
|
|
|
|
editor.len = editor.pos;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.pos < editor.start)
|
2008-07-09 09:34:12 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.end = editor.pos;
|
|
|
|
editor.start = editor.end - editlinewidth;
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.start < 0)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.end -= editor.start;
|
|
|
|
editor.start = 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
else if (editor.pos >= editor.end)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.start += (editor.pos - editor.end);
|
|
|
|
editor.end += (editor.pos - editor.end);
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
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
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
if (!osd || (osd->flags & OSD_CAPTURE) != OSD_CAPTURE)
|
2010-05-02 23:27:30 +00:00
|
|
|
return ch;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
osdhist_t &history = osd->history;
|
|
|
|
osdedit_t &editor = osd->editor;
|
|
|
|
|
|
|
|
osdsymbol_t * tabc = NULL;
|
|
|
|
static osdsymbol_t *lastmatch = NULL;
|
|
|
|
|
|
|
|
if (ch != asc_Tab)
|
2010-05-02 23:27:30 +00:00
|
|
|
lastmatch = NULL;
|
|
|
|
|
|
|
|
switch (ch)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
case asc_Ctrl_A: // jump to beginning of line
|
|
|
|
editor.pos = 0;
|
|
|
|
editor.start = 0;
|
|
|
|
editor.end = editlinewidth;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_B: // move one character left
|
|
|
|
if (editor.pos > 0)
|
|
|
|
editor.pos--;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_C: // discard line
|
|
|
|
editor.buf[editor.len] = 0;
|
|
|
|
OSD_Printf("%s\n", editor.buf);
|
|
|
|
|
|
|
|
editor.len = 0;
|
|
|
|
editor.pos = 0;
|
|
|
|
editor.start = 0;
|
|
|
|
editor.end = editlinewidth;
|
|
|
|
editor.buf[0] = 0;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_E: // jump to end of line
|
|
|
|
editor.pos = editor.len;
|
|
|
|
editor.end = editor.pos;
|
|
|
|
editor.start = editor.end - editlinewidth;
|
|
|
|
|
|
|
|
if (editor.start < 0)
|
|
|
|
{
|
|
|
|
editor.start = 0;
|
|
|
|
editor.end = editlinewidth;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_F: // move one character right
|
|
|
|
if (editor.pos < editor.len)
|
|
|
|
editor.pos++;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_BackSpace:
|
2011-06-17 11:53:41 +00:00
|
|
|
#ifdef __APPLE__
|
2017-06-27 02:24:14 +00:00
|
|
|
case 127: // control h, backspace
|
2011-06-17 11:53:41 +00:00
|
|
|
#endif
|
2017-06-27 02:24:14 +00:00
|
|
|
if (!editor.pos || !editor.len)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((osd->flags & OSD_OVERTYPE) == 0)
|
|
|
|
{
|
|
|
|
if (editor.pos < editor.len)
|
|
|
|
Bmemmove(editor.buf + editor.pos - 1, editor.buf + editor.pos, editor.len - editor.pos);
|
|
|
|
editor.len--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (--editor.pos < editor.start)
|
|
|
|
editor.start--, editor.end--;
|
2017-07-18 20:53:41 +00:00
|
|
|
fallthrough__;
|
2011-06-17 11:53:41 +00:00
|
|
|
#ifndef __APPLE__
|
2017-06-27 02:24:14 +00:00
|
|
|
case 127: // handled in OSD_HandleScanCode (delete)
|
2011-06-17 11:53:41 +00:00
|
|
|
#endif
|
2017-06-27 02:24:14 +00:00
|
|
|
return 0;
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
case asc_Tab: // tab
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t commonsize = 512;
|
2008-07-01 10:31:03 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (!lastmatch)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int editPos, iter;
|
|
|
|
|
|
|
|
for (editPos = editor.pos; editPos > 0; editPos--)
|
|
|
|
if (editor.buf[editPos - 1] == ' ')
|
|
|
|
break;
|
|
|
|
|
|
|
|
for (iter = 0; editPos < editor.len && editor.buf[editPos] != ' '; iter++, editPos++)
|
|
|
|
editor.tmp[iter] = editor.buf[editPos];
|
|
|
|
|
|
|
|
editor.tmp[iter] = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (iter > 0)
|
2006-12-11 03:06:49 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
tabc = osd_findsymbol(editor.tmp, NULL);
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (tabc && tabc->next && osd_findsymbol(editor.tmp, tabc->next))
|
2006-12-11 03:06:49 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdsymbol_t *symb = tabc;
|
|
|
|
int32_t maxwidth = 0, x = 0, num = 0, diffpt;
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
while (symb && symb != lastmatch)
|
2008-07-09 09:34:12 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +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 = osd_findsymbol(editor.tmp, lastmatch->next);
|
2008-07-09 09:34:12 +00:00
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%sFound %d possible completions for \"%s\":\n", osd->draw.highlight, num, editor.tmp);
|
|
|
|
maxwidth += 3;
|
|
|
|
symb = tabc;
|
|
|
|
OSD_Printf(" ");
|
|
|
|
|
|
|
|
while (symb && (symb != lastmatch))
|
2008-07-09 09:34:12 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
tabc = lastmatch = symb;
|
|
|
|
OSD_Printf("%-*s", maxwidth, symb->name);
|
|
|
|
|
|
|
|
if (!lastmatch->next)
|
|
|
|
break;
|
|
|
|
|
|
|
|
symb = osd_findsymbol(editor.tmp, lastmatch->next);
|
|
|
|
x += maxwidth;
|
|
|
|
|
|
|
|
if (x > (osd->draw.cols - maxwidth))
|
|
|
|
{
|
|
|
|
x = 0;
|
|
|
|
OSD_Printf("\n");
|
|
|
|
|
|
|
|
if (symb && (symb != lastmatch))
|
|
|
|
OSD_Printf(" ");
|
|
|
|
}
|
2006-12-11 03:06:49 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
if (x)
|
|
|
|
OSD_Printf("\n");
|
|
|
|
|
|
|
|
OSD_Printf("%sPress TAB again to cycle through matches\n", osd->draw.highlight);
|
2006-12-11 03:06:49 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
else
|
2011-01-16 02:50:27 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
tabc = osd_findsymbol(editor.tmp, lastmatch->next);
|
|
|
|
|
|
|
|
if (!tabc && lastmatch)
|
|
|
|
tabc = osd_findsymbol(editor.tmp, NULL); // wrap */
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (tabc)
|
2008-07-07 12:17:27 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int editPos;
|
|
|
|
|
|
|
|
for (editPos = editor.pos; editPos > 0; editPos--)
|
|
|
|
if (editor.buf[editPos - 1] == ' ')
|
|
|
|
break;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.len = editPos;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
for (int iter = 0; tabc->name[iter] && editor.len <= OSDEDITLENGTH - 1 && (editor.len < commonsize); editPos++, iter++, editor.len++)
|
|
|
|
editor.buf[editPos] = tabc->name[iter];
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.pos = editor.len;
|
|
|
|
editor.end = editor.pos;
|
|
|
|
editor.start = editor.end - editlinewidth;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.start < 0)
|
|
|
|
{
|
|
|
|
editor.start = 0;
|
|
|
|
editor.end = editlinewidth;
|
|
|
|
}
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
lastmatch = tabc;
|
2008-07-07 12:17:27 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
case asc_Ctrl_K: // delete all to end of line
|
|
|
|
Bmemset(editor.buf + editor.pos, 0, OSDEDITLENGTH - editor.pos);
|
|
|
|
editor.len = editor.pos;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_L: // clear screen
|
|
|
|
Bmemset(osd->text.buf, 0, OSDBUFFERSIZE);
|
|
|
|
Bmemset(osd->text.fmt, osd->draw.textpal + (osd->draw.textshade << 5), OSDBUFFERSIZE);
|
|
|
|
osd->text.lines = 1;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Enter: // control m, enter
|
|
|
|
if (editor.len > 0)
|
2008-07-07 12:17:27 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.buf[editor.len] = 0;
|
|
|
|
if (!history.buf[0] || Bstrcmp(history.buf[0], editor.buf))
|
|
|
|
{
|
|
|
|
DO_FREE_AND_NULL(history.buf[history.maxlines - 1]);
|
|
|
|
Bmemmove(&history.buf[1], &history.buf[0], sizeof(intptr_t) * history.maxlines - 1);
|
|
|
|
OSD_SetHistory(0, editor.buf);
|
|
|
|
|
|
|
|
if (history.lines < history.maxlines)
|
|
|
|
history.lines++;
|
|
|
|
|
|
|
|
history.total++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (history.exec++ == history.maxlines)
|
|
|
|
OSD_Printf("Buffer full! Consider increasing \"osdhistorydepth\" beyond %d.\n", --history.exec);
|
|
|
|
|
|
|
|
history.pos = -1;
|
2008-07-07 12:17:27 +00:00
|
|
|
}
|
2008-07-04 02:13:48 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.len = 0;
|
|
|
|
editor.pos = 0;
|
|
|
|
editor.start = 0;
|
|
|
|
editor.end = editlinewidth;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_N: // next (ie. down arrow)
|
|
|
|
OSD_HistoryNext();
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_P: // previous (ie. up arrow)
|
|
|
|
OSD_HistoryPrev();
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_U: // delete all to beginning
|
|
|
|
if (editor.pos > 0 && editor.len)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.pos < editor.len)
|
|
|
|
Bmemmove(editor.buf, editor.buf + editor.pos, editor.len - editor.pos);
|
|
|
|
|
|
|
|
editor.len -= editor.pos;
|
|
|
|
editor.pos = 0;
|
|
|
|
editor.start = 0;
|
|
|
|
editor.end = editlinewidth;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_W: // delete one word back
|
|
|
|
if (editor.pos > 0 && editor.len > 0)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int editPos = editor.pos;
|
|
|
|
|
|
|
|
while (editPos > 0 && editor.buf[editPos - 1] == asc_Space) editPos--;
|
|
|
|
while (editPos > 0 && editor.buf[editPos - 1] != asc_Space) editPos--;
|
|
|
|
|
|
|
|
if (editor.pos < editor.len)
|
|
|
|
Bmemmove(editor.buf + editPos, editor.buf + editor.pos, editor.len - editor.pos);
|
|
|
|
|
|
|
|
editor.len -= (editor.pos - editPos);
|
|
|
|
editor.pos = editPos;
|
|
|
|
|
|
|
|
if (editor.pos < editor.start)
|
|
|
|
{
|
|
|
|
editor.start = editor.pos;
|
|
|
|
editor.end = editor.start + editlinewidth;
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
return 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
default:
|
|
|
|
if (ch >= asc_Space) // text char
|
|
|
|
{
|
|
|
|
if ((osd->flags & OSD_OVERTYPE) == 0)
|
|
|
|
{
|
|
|
|
if (editor.len == OSDEDITLENGTH) // buffer full, can't insert another char
|
|
|
|
return 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.pos < editor.len)
|
|
|
|
Bmemmove(editor.buf + editor.pos + 1, editor.buf + editor.pos, editor.len - editor.pos);
|
|
|
|
|
|
|
|
editor.len++;
|
|
|
|
}
|
|
|
|
else if (editor.pos == editor.len)
|
|
|
|
editor.len++;
|
|
|
|
|
|
|
|
editor.buf[editor.pos++] = ch;
|
|
|
|
|
|
|
|
if (editor.pos > editor.end)
|
|
|
|
editor.start++, editor.end++;
|
|
|
|
}
|
|
|
|
return 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2008-07-02 01:32:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
int OSD_HandleScanCode(uint8_t scanCode, int keyDown)
|
2008-07-02 01:32:53 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
if (!osd)
|
2014-01-27 10:30:25 +00:00
|
|
|
return 1;
|
2008-07-02 01:32:53 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
osddraw_t &draw = osd->draw;
|
|
|
|
|
2017-07-05 05:42:37 +00:00
|
|
|
if (scanCode == osd->keycode && (keystatus[sc_LeftShift] || (osd->flags & OSD_CAPTURE) || (osd->flags & OSD_PROTECTED) != OSD_PROTECTED))
|
2008-07-02 01:32:53 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (keyDown)
|
2008-07-02 01:32:53 +00:00
|
|
|
{
|
2017-06-27 11:01:22 +00:00
|
|
|
draw.scrolling = (osdrowscur == -1) ? 1 :
|
2017-06-27 02:24:14 +00:00
|
|
|
(osdrowscur == draw.rows) ? -1 :
|
|
|
|
-draw.scrolling;
|
|
|
|
osdrowscur += draw.scrolling;
|
|
|
|
OSD_CaptureInput(draw.scrolling == 1);
|
2008-07-02 01:32:53 +00:00
|
|
|
osdscrtime = getticks();
|
|
|
|
}
|
2014-01-27 10:30:25 +00:00
|
|
|
return -1;
|
2008-07-02 01:32:53 +00:00
|
|
|
}
|
2014-07-06 00:12:25 +00:00
|
|
|
else if ((osd->flags & OSD_CAPTURE) == 0)
|
2014-01-27 10:30:25 +00:00
|
|
|
return 2;
|
2008-07-02 01:32:53 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (!keyDown)
|
2008-07-02 01:32:53 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (scanCode == sc_LeftShift || scanCode == sc_RightShift)
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->flags &= ~OSD_SHIFT;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
if (scanCode == sc_LeftControl || scanCode == sc_RightControl)
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->flags &= ~OSD_CTRL;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
2008-07-02 01:32:53 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
osdedit_t &editor = osd->editor;
|
2008-07-02 01:32:53 +00:00
|
|
|
keytime = gettime();
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
switch (scanCode)
|
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);
|
2017-06-27 02:24:14 +00:00
|
|
|
draw.scrolling = -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;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_PgUp:
|
2017-06-27 02:24:14 +00:00
|
|
|
if (draw.head < osd->text.lines-1)
|
|
|
|
draw.head++;
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_PgDn:
|
2017-06-27 02:24:14 +00:00
|
|
|
if (draw.head > 0)
|
|
|
|
draw.head--;
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_Home:
|
2014-07-06 00:12:25 +00:00
|
|
|
if (osd->flags & OSD_CTRL)
|
2017-06-27 02:24:14 +00:00
|
|
|
draw.head = osd->text.lines-1;
|
2007-12-12 17:42:14 +00:00
|
|
|
else
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.pos = 0;
|
|
|
|
editor.start = editor.pos;
|
|
|
|
editor.end = editor.start + editlinewidth;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_End:
|
2014-07-06 00:12:25 +00:00
|
|
|
if (osd->flags & OSD_CTRL)
|
2017-06-27 02:24:14 +00:00
|
|
|
draw.head = 0;
|
2007-12-12 17:42:14 +00:00
|
|
|
else
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.pos = editor.len;
|
|
|
|
editor.end = editor.pos;
|
|
|
|
editor.start = editor.end - editlinewidth;
|
|
|
|
|
|
|
|
if (editor.start < 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.start = 0;
|
|
|
|
editor.end = editlinewidth;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_Insert:
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->flags = (osd->flags & ~OSD_OVERTYPE) | (-((osd->flags & OSD_OVERTYPE) == 0) & OSD_OVERTYPE);
|
2010-05-18 05:14:17 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_LeftArrow:
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.pos > 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
if (osd->flags & OSD_CTRL)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
while (editor.pos > 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.buf[editor.pos-1] != asc_Space)
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
editor.pos--;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
while (editor.pos > 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.buf[editor.pos-1] == asc_Space)
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
editor.pos--;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
else editor.pos--;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
if (editor.pos < editor.start)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.end -= (editor.start - editor.pos);
|
|
|
|
editor.start -= (editor.start - editor.pos);
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_RightArrow:
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.pos < editor.len)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
if (osd->flags & OSD_CTRL)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
while (editor.pos < editor.len)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.buf[editor.pos] == asc_Space)
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
editor.pos++;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
while (editor.pos < editor.len)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.buf[editor.pos] != asc_Space)
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
editor.pos++;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
else editor.pos++;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
if (editor.pos >= editor.end)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
editor.start += (editor.pos - editor.end);
|
|
|
|
editor.end += (editor.pos - editor.end);
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_UpArrow:
|
2008-07-08 04:52:39 +00:00
|
|
|
OSD_HistoryPrev();
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_DownArrow:
|
2008-07-08 04:52:39 +00:00
|
|
|
OSD_HistoryNext();
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_LeftShift:
|
|
|
|
case sc_RightShift:
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->flags |= OSD_SHIFT;
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_LeftControl:
|
|
|
|
case sc_RightControl:
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->flags |= OSD_CTRL;
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_CapsLock:
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->flags = (osd->flags & ~OSD_CAPS) | (-((osd->flags & OSD_CAPS) == 0) & OSD_CAPS);
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2010-05-02 23:27:30 +00:00
|
|
|
case sc_Delete:
|
2017-06-27 02:24:14 +00:00
|
|
|
if (editor.pos == editor.len || !editor.len)
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
if (editor.pos <= editor.len-1)
|
|
|
|
Bmemmove(editor.buf+editor.pos, editor.buf+editor.pos+1, editor.len-editor.pos-1);
|
|
|
|
|
|
|
|
editor.len--;
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
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
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
int32_t newcols, newmaxlines;
|
|
|
|
char *newtext, *newfmt;
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t i,j,k;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
newcols = getcolumnwidth(w);
|
2014-07-06 00:12:25 +00:00
|
|
|
newmaxlines = OSDBUFFERSIZE / newcols;
|
|
|
|
|
|
|
|
j = min(newmaxlines, osd->text.maxlines);
|
|
|
|
k = min(newcols, osd->draw.cols);
|
|
|
|
|
|
|
|
newtext = (char *)Bmalloc(OSDBUFFERSIZE);
|
|
|
|
newfmt = (char *)Bmalloc(OSDBUFFERSIZE);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
Bmemset(newtext, asc_Space, OSDBUFFERSIZE);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2009-02-19 16:47:54 +00:00
|
|
|
for (i=j-1; i>=0; i--)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
Bmemcpy(newtext+newcols*i, osd->text.buf+osd->draw.cols*i, k);
|
|
|
|
Bmemcpy(newfmt+newcols*i, osd->text.fmt+osd->draw.cols*i, k);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
Bfree(osd->text.buf);
|
|
|
|
osd->text.buf = newtext;
|
|
|
|
|
|
|
|
Bfree(osd->text.fmt);
|
|
|
|
osd->text.fmt = newfmt;
|
|
|
|
|
|
|
|
osd->text.maxlines = newmaxlines;
|
|
|
|
|
|
|
|
osd->draw.cols = newcols;
|
2006-04-24 19:04:22 +00:00
|
|
|
osdmaxrows = getrowheight(h)-2;
|
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (osd->draw.rows > osdmaxrows) osd->draw.rows = osdmaxrows;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->text.pos = 0;
|
|
|
|
osd->draw.head = 0;
|
|
|
|
osd->editor.start = 0;
|
|
|
|
osd->editor.end = editlinewidth;
|
2017-06-27 02:24:14 +00:00
|
|
|
whiteColorIdx = -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
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->flags = (osd->flags & ~(OSD_CAPTURE|OSD_CTRL|OSD_SHIFT)) | (-cap & OSD_CAPTURE);
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2014-11-17 07:39:12 +00:00
|
|
|
grabmouse(cap == 0 ? AppMouseGrab : 0);
|
2010-05-02 23:27:30 +00:00
|
|
|
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
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->flags = (osd->flags & ~OSD_DRAW) | (-onf & OSD_DRAW);
|
2010-05-02 23:27:30 +00:00
|
|
|
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
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (!osd)
|
2010-05-02 23:27:30 +00:00
|
|
|
return;
|
2006-12-11 03:06:49 +00:00
|
|
|
|
2006-12-11 21:18:21 +00:00
|
|
|
if (osdrowscur == 0)
|
2014-07-06 00:12:25 +00:00
|
|
|
OSD_ShowDisplay(osd->flags & OSD_DRAW ? 0 : 1);
|
2006-12-11 03:06:49 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (osdrowscur == osd->draw.rows)
|
2017-06-27 02:24:14 +00:00
|
|
|
osd->draw.scrolling = 0;
|
2006-12-11 03:06:49 +00:00
|
|
|
else
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if ((osdrowscur < osd->draw.rows && osd->draw.scrolling == 1) || osdrowscur < -1)
|
2007-01-06 09:50:02 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t j = (getticks()-osdscrtime);
|
|
|
|
while (j >= 0)
|
2007-01-06 09:50:02 +00:00
|
|
|
{
|
|
|
|
osdrowscur++;
|
2014-10-25 03:29:21 +00:00
|
|
|
j -= tabledivide32_noinline(200, osd->draw.rows);
|
2014-07-06 00:12:25 +00:00
|
|
|
if (osdrowscur > osd->draw.rows-1)
|
2007-01-06 09:50:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
else if ((osdrowscur > -1 && osd->draw.scrolling == -1) || osdrowscur > osd->draw.rows)
|
2007-01-06 09:50:02 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t j = (getticks()-osdscrtime);
|
|
|
|
while (j >= 0)
|
2007-01-06 09:50:02 +00:00
|
|
|
{
|
|
|
|
osdrowscur--;
|
2014-10-25 03:29:21 +00:00
|
|
|
j -= tabledivide32_noinline(200, osd->draw.rows);
|
2007-01-06 09:50:02 +00:00
|
|
|
if (osdrowscur < 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2007-01-06 09:50:02 +00:00
|
|
|
osdscrtime = getticks();
|
2007-01-02 02:27:31 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if ((osd->flags & OSD_DRAW) == 0 || !osdrowscur) return;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
topoffs = osd->draw.head * osd->draw.cols;
|
2006-12-11 03:06:49 +00:00
|
|
|
row = osdrowscur-1;
|
2014-07-06 00:12:25 +00:00
|
|
|
lines = min(osd->text.lines-osd->draw.head, osdrowscur);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
begindrawing();
|
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
clearbackground(osd->draw.cols,osdrowscur+1);
|
2007-12-12 17:42:14 +00:00
|
|
|
|
|
|
|
for (; lines>0; lines--, row--)
|
|
|
|
{
|
2013-12-24 09:44:20 +00:00
|
|
|
// XXX: May happen, which would ensue an oob if not checked.
|
2014-07-06 00:12:25 +00:00
|
|
|
// Last char accessed is osd->text.buf[topoffs + osd->draw.cols-1].
|
2013-12-24 09:44:20 +00:00
|
|
|
// Reproducible by running test.lua with -Lopts=diag
|
|
|
|
// and scrolling to the top.
|
2014-07-06 00:12:25 +00:00
|
|
|
if (topoffs + osd->draw.cols-1 >= OSDBUFFERSIZE)
|
2013-12-24 09:44:20 +00:00
|
|
|
break;
|
2014-07-06 00:12:25 +00:00
|
|
|
drawosdstr(0,row,osd->text.buf+topoffs,osd->draw.cols,osd->draw.textshade,osd->draw.textpal);
|
|
|
|
topoffs+=osd->draw.cols;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2008-10-11 09:20:04 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
int32_t offset = ((osd->flags & (OSD_CAPS|OSD_SHIFT)) == (OSD_CAPS|OSD_SHIFT) && osd->draw.head > 0);
|
|
|
|
int32_t shade = osd->draw.promptshade?osd->draw.promptshade:(sintable[(totalclock<<4)&2047]>>11);
|
2008-10-11 09:20:04 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (osd->draw.head == osd->text.lines-1) drawosdchar(0,osdrowscur,'~',shade,osd->draw.promptpal);
|
|
|
|
else if (osd->draw.head > 0) drawosdchar(0,osdrowscur,'^',shade,osd->draw.promptpal);
|
|
|
|
if (osd->flags & OSD_CAPS) drawosdchar(0+(osd->draw.head > 0),osdrowscur,'C',shade,osd->draw.promptpal);
|
|
|
|
if (osd->flags & OSD_SHIFT) drawosdchar(1+(osd->flags & OSD_CAPS && osd->draw.head > 0),osdrowscur,'H',shade,osd->draw.promptpal);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
drawosdchar(2+offset,osdrowscur,'>',shade,osd->draw.promptpal);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
len = min(osd->draw.cols-1-3-offset, osd->editor.len-osd->editor.start);
|
2008-10-11 09:20:04 +00:00
|
|
|
for (x=len-1; x>=0; x--)
|
2017-06-27 02:24:14 +00:00
|
|
|
drawosdchar(3+x+offset,osdrowscur, osd->editor.buf[osd->editor.start+x],osd->draw.editshade<<1,osd->draw.editpal);
|
2008-10-11 09:20:04 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
offset += 3+osd->editor.pos-osd->editor.start;
|
2010-05-25 10:56:00 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
drawosdcursor(offset,osdrowscur,osd->flags & OSD_OVERTYPE,keytime);
|
2010-05-25 10:56:00 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (osd->version.buf)
|
|
|
|
drawosdstr(osd->draw.cols - osd->version.len, osdrowscur - (offset >= osd->draw.cols - osd->version.len),
|
|
|
|
osd->version.buf, osd->version.len, (sintable[(totalclock<<4)&2047]>>11), osd->version.pal);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2014-07-24 14:01:44 +00:00
|
|
|
// OSD_Printf() -- Print a formatted string to the onscreen display
|
|
|
|
// and write it to the log file
|
|
|
|
//
|
|
|
|
|
|
|
|
void OSD_Printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
static char tmpstr[8192];
|
|
|
|
va_list va;
|
|
|
|
|
|
|
|
va_start(va, fmt);
|
|
|
|
Bvsnprintf(tmpstr, sizeof(tmpstr), fmt, va);
|
|
|
|
va_end(va);
|
|
|
|
|
|
|
|
OSD_Puts(tmpstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_Puts() -- Print a string to the onscreen display
|
2006-04-13 20:47:06 +00:00
|
|
|
// 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
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
Bmemmove(osd->text.buf + osd->draw.cols, osd->text.buf, OSDBUFFERSIZE - osd->draw.cols);
|
2014-07-06 00:12:25 +00:00
|
|
|
Bmemset(osd->text.buf, asc_Space, osd->draw.cols);
|
2017-06-27 02:24:14 +00:00
|
|
|
Bmemmove(osd->text.fmt + osd->draw.cols, osd->text.fmt, OSDBUFFERSIZE - osd->draw.cols);
|
2014-07-06 00:12:25 +00:00
|
|
|
Bmemset(osd->text.fmt, osd->draw.textpal, osd->draw.cols);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
if (osd->text.lines < osd->text.maxlines)
|
|
|
|
osd->text.lines++;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
2014-07-24 14:01:44 +00:00
|
|
|
|
2008-08-23 15:37:30 +00:00
|
|
|
#define MAX_ERRORS 4096
|
2014-07-24 14:01:44 +00:00
|
|
|
|
|
|
|
void OSD_Puts(const char *tmpstr)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (tmpstr[0]==0)
|
|
|
|
return;
|
|
|
|
|
2014-07-24 14:01:44 +00:00
|
|
|
const char *chp;
|
2017-06-27 02:24:14 +00:00
|
|
|
uint8_t textPal = osd->draw.textpal;
|
|
|
|
uint8_t textShade = osd->draw.textshade;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
mutex_lock(&osd->mutex);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
osdlog_t &log = osd->log;
|
2012-12-25 16:13:36 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (tmpstr[0]=='^' && tmpstr[1]=='1' && tmpstr[2]=='0' && ++log.errors > MAX_ERRORS)
|
2008-08-23 15:37:30 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (log.errors == MAX_ERRORS + 1)
|
2014-07-24 14:01:44 +00:00
|
|
|
tmpstr = "\nToo many errors. Logging errors stopped.\n";
|
2008-08-24 06:17:09 +00:00
|
|
|
else
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
log.errors = MAX_ERRORS + 2;
|
2014-07-06 00:12:25 +00:00
|
|
|
mutex_unlock(&osd->mutex);
|
2008-08-24 06:17:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-08-23 15:37:30 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (log.lines < log.cutoff)
|
2008-01-04 01:04:35 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (osdlog && (!log.cutoff || log.lines < log.cutoff))
|
2008-08-03 11:45:15 +00:00
|
|
|
{
|
2014-07-24 14:01:44 +00:00
|
|
|
char *chp2 = Xstrdup(tmpstr);
|
|
|
|
Bfputs(OSD_StripColors(chp2, tmpstr), osdlog);
|
|
|
|
Bprintf("%s", chp2);
|
|
|
|
Bfree(chp2);
|
2008-08-03 11:45:15 +00:00
|
|
|
}
|
2008-01-04 01:04:35 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
else if (log.lines == log.cutoff)
|
2008-01-04 01:04:35 +00:00
|
|
|
{
|
2017-07-08 19:41:29 +00:00
|
|
|
Bfputs("\nLog file full! Consider increasing \"osdlogcutoff\".\n", osdlog);
|
2017-06-27 02:24:14 +00:00
|
|
|
log.lines = log.cutoff + 1;
|
2008-01-04 01:04:35 +00:00
|
|
|
}
|
|
|
|
|
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')
|
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->text.pos=0;
|
2017-06-27 02:24:14 +00:00
|
|
|
log.lines++;
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_LineFeed();
|
2008-08-24 05:39:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2008-08-24 05:39:28 +00:00
|
|
|
if (*chp == '\r')
|
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->text.pos=0;
|
2008-08-24 05:39:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2008-08-24 05:39:28 +00:00
|
|
|
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';
|
2017-06-27 02:24:14 +00:00
|
|
|
textPal = Batoi(smallbuf);
|
2008-08-24 09:29:03 +00:00
|
|
|
continue;
|
2008-08-24 05:39:28 +00:00
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2008-08-24 09:29:03 +00:00
|
|
|
smallbuf[0] = *(chp++);
|
|
|
|
smallbuf[1] = *(chp);
|
|
|
|
smallbuf[2] = '\0';
|
2017-06-27 02:24:14 +00:00
|
|
|
textPal = Batoi(smallbuf);
|
2008-08-24 05:39:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2008-08-24 05:39:28 +00:00
|
|
|
if (Btoupper(*(chp+1)) == 'S')
|
|
|
|
{
|
|
|
|
chp++;
|
|
|
|
if (isdigit(*(++chp)))
|
2017-06-27 02:24:14 +00:00
|
|
|
textShade = *chp;
|
2008-08-24 05:39:28 +00:00
|
|
|
continue;
|
2008-07-18 09:50:44 +00:00
|
|
|
}
|
2011-01-16 02:50:27 +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++;
|
2017-06-27 02:24:14 +00:00
|
|
|
textPal = osd->draw.textpal;
|
|
|
|
textShade = osd->draw.textshade;
|
2008-08-24 05:39:28 +00:00
|
|
|
continue;
|
2008-07-18 09:50:44 +00:00
|
|
|
}
|
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->text.buf[osd->text.pos] = *chp;
|
2017-06-27 02:24:14 +00:00
|
|
|
osd->text.fmt[osd->text.pos++] = textPal+(textShade<<5);
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (osd->text.pos == osd->draw.cols)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->text.pos = 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));
|
2010-06-22 21:50:01 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
mutex_unlock(&osd->mutex);
|
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
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (!osd->history.exec) return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
cmd = osd->history.exec-1;
|
|
|
|
osd->history.exec = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
for (; cmd>=0; cmd--)
|
2014-07-06 00:12:25 +00:00
|
|
|
OSD_Dispatch((const char *)osd->history.buf[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
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
#define MAXPARMS 256
|
2009-01-09 09:29:17 +00:00
|
|
|
int32_t OSD_Dispatch(const char *cmd)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
char *workbuf, *wtp, *state;
|
|
|
|
char const *pszParam;
|
2010-05-09 08:51:25 +00:00
|
|
|
int32_t restart = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-05-30 00:02:19 +00:00
|
|
|
workbuf = state = Xstrdup(cmd);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
do
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if ((pszParam = strtoken(state, &wtp, &restart)) == NULL)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
state = wtp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
// cheap hack for comments in cfgs
|
|
|
|
if (pszParam[0] == '/' && pszParam[1] == '/')
|
2008-06-29 12:53:18 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
Bfree(workbuf);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
osdsymbol_t const * const pSymbol = osd_findexactsymbol(pszParam);
|
|
|
|
|
|
|
|
if (pSymbol == NULL)
|
|
|
|
{
|
|
|
|
static char const s_gamefunc_[] = "gamefunc_";
|
|
|
|
size_t const strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1;
|
|
|
|
size_t const strlen_token = Bstrlen(pszParam);
|
|
|
|
|
|
|
|
if ((strlen_gamefunc_ >= strlen_token || Bstrncmp(pszParam, s_gamefunc_, strlen_gamefunc_)) && !m32_osd_tryscript)
|
|
|
|
OSD_Printf("%s\"%s\" is not a valid command or cvar\n", osd->draw.highlight, pszParam);
|
2010-05-22 23:41:18 +00:00
|
|
|
else if (m32_osd_tryscript)
|
|
|
|
M32RunScript(cmd);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2009-10-07 06:47:35 +00:00
|
|
|
Bfree(workbuf);
|
2006-04-24 19:04:22 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
char const * const pszName = pszParam;
|
|
|
|
char const *parms[MAXPARMS];
|
|
|
|
|
|
|
|
Bmemset(parms, 0, sizeof(parms));
|
|
|
|
|
|
|
|
int32_t numparms = 0;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
while (wtp && !restart)
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
pszParam = strtoken(NULL, &wtp, &restart);
|
|
|
|
if (pszParam && numparms < MAXPARMS) parms[numparms++] = pszParam;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
osdfuncparm_t const ofp ={ numparms, pszName, (const char **) parms, cmd };
|
|
|
|
|
|
|
|
if (pSymbol->func == OSD_ALIAS)
|
|
|
|
OSD_Dispatch(pSymbol->help);
|
|
|
|
else if (pSymbol->func != OSD_UNALIASED)
|
|
|
|
{
|
|
|
|
switch (pSymbol->func(&ofp))
|
2008-06-30 00:18:59 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
case OSDCMD_OK: break;
|
|
|
|
case OSDCMD_SHOWHELP: OSD_Printf("%s\n", pSymbol->help); break;
|
2008-06-30 00:18:59 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
}
|
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
|
|
|
|
//
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t OSD_RegisterFunction(const char *pszName, const char *pszDesc, int32_t (*func)(const osdfuncparm_t*))
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdsymbol_t *symb;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
if (!osd)
|
2010-05-02 23:27:30 +00:00
|
|
|
OSD_Init();
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
symb = osd_findexactsymbol(pszName);
|
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
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
symb->help = pszDesc;
|
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
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
symb = osd_addsymbol(pszName);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
symb->name = pszName;
|
|
|
|
symb->help = pszDesc;
|
2006-04-24 19:04:22 +00:00
|
|
|
symb->func = func;
|
|
|
|
|
|
|
|
return 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2006-12-11 04:38:10 +00:00
|
|
|
//
|
|
|
|
// OSD_SetVersionString()
|
|
|
|
//
|
2017-06-27 02:24:14 +00:00
|
|
|
void OSD_SetVersion(const char *pszVersion, int osdShade, int osdPal)
|
2006-12-11 04:38:10 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
DO_FREE_AND_NULL(osd->version.buf);
|
|
|
|
osd->version.buf = Bstrdup(pszVersion);
|
|
|
|
osd->version.len = Bstrlen(pszVersion);
|
|
|
|
osd->version.shade = osdShade;
|
|
|
|
osd->version.pal = osdPal;
|
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
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
static osdsymbol_t *osd_addsymbol(const char *pszName)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (osd->numsymbols >= OSDMAXSYMBOLS)
|
|
|
|
return NULL;
|
|
|
|
osdsymbol_t *const pSymbol = (osdsymbol_t *)Xcalloc(1, sizeof(osdsymbol_t));
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
// link it to the main chain
|
2007-12-12 17:42:14 +00:00
|
|
|
if (!symbols)
|
2017-06-27 02:24:14 +00:00
|
|
|
symbols = pSymbol;
|
2007-12-12 17:42:14 +00:00
|
|
|
else
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (Bstrcasecmp(pszName, symbols->name) <= 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdsymbol_t * const t = symbols;
|
|
|
|
symbols = pSymbol;
|
2006-04-24 19:04:22 +00:00
|
|
|
symbols->next = t;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdsymbol_t *s = symbols;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
while (s->next)
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (Bstrcasecmp(s->next->name, pszName) > 0) break;
|
2006-04-24 19:04:22 +00:00
|
|
|
s=s->next;
|
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
osdsymbol_t * const t = s->next;
|
|
|
|
|
|
|
|
s->next = pSymbol;
|
|
|
|
pSymbol->next = t;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
char * const lowercase = Bstrtolower(Xstrdup(pszName));
|
|
|
|
|
|
|
|
hash_add(&h_osd, pszName, osd->numsymbols, 1);
|
|
|
|
hash_add(&h_osd, lowercase, osd->numsymbols, 1);
|
|
|
|
Bfree(lowercase);
|
|
|
|
|
|
|
|
osd->symbptrs[osd->numsymbols++] = pSymbol;
|
|
|
|
|
|
|
|
return pSymbol;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// findsymbol() -- Finds a symbol, possibly partially named
|
2006-04-24 19:04:22 +00:00
|
|
|
//
|
2017-06-27 02:24:14 +00:00
|
|
|
static osdsymbol_t * osd_findsymbol(const char *pszName, osdsymbol_t *pSymbol)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (!pSymbol) pSymbol = symbols;
|
|
|
|
if (!pSymbol) return NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
for (; pSymbol; pSymbol=pSymbol->next)
|
|
|
|
if (pSymbol->func != OSD_UNALIASED && !Bstrncasecmp(pszName, pSymbol->name, Bstrlen(pszName))) return pSymbol;
|
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
|
|
|
//
|
2017-06-27 02:24:14 +00:00
|
|
|
static osdsymbol_t * osd_findexactsymbol(const char *pszName)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
if (!symbols) return NULL;
|
2017-06-27 02:24:14 +00:00
|
|
|
int symbolNum = hash_find(&h_osd, pszName);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (symbolNum < 0)
|
2008-08-25 02:33:25 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
char *const lname = Xstrdup(pszName);
|
|
|
|
Bstrtolower(lname);
|
|
|
|
symbolNum = hash_find(&h_osd, lname);
|
2008-10-18 12:37:26 +00:00
|
|
|
Bfree(lname);
|
2008-08-25 02:33:25 +00:00
|
|
|
}
|
2008-12-31 09:07:49 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
return (symbolNum >= 0) ? osd->symbptrs[symbolNum] : NULL;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t osdcmd_cvar_set(osdfuncparm_t const * const parm)
|
2009-04-29 06:20:07 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int const printValue = (parm->numparms == 0);
|
|
|
|
int const cvaridx = hash_find(&h_cvars, parm->name);
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
#if 0
|
2009-04-29 06:20:07 +00:00
|
|
|
if (i < 0)
|
2014-07-06 00:12:25 +00:00
|
|
|
for (i = osd->numcvars-1; i >= 0; i--)
|
2017-06-27 02:24:14 +00:00
|
|
|
if (!Bstrcasecmp(parm->name, pData.name)) break;
|
|
|
|
#endif
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (cvaridx >= 0)
|
2009-04-29 06:20:07 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdcvardata_t &pData = *osd->cvars[cvaridx].pData;
|
|
|
|
|
|
|
|
if (pData.flags & CVAR_READONLY)
|
2009-04-29 06:20:07 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("Cvar \"%s\" is read only.\n", pData.name);
|
2009-04-29 06:20:07 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2009-04-30 21:09:44 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
switch (pData.flags & CVAR_TYPEMASK)
|
2009-04-30 21:09:44 +00:00
|
|
|
{
|
|
|
|
case CVAR_FLOAT:
|
2009-06-24 08:20:10 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (printValue)
|
2009-06-24 08:20:10 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("\"%s\" is \"%f\"\n%s: %s\n", pData.name, *pData.f, pData.name, pData.desc);
|
2009-06-24 08:20:10 +00:00
|
|
|
return OSDCMD_OK;
|
2009-04-30 01:07:08 +00:00
|
|
|
}
|
2016-12-01 04:06:40 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
Bsscanf(parm->parms[0], "%f", pData.f);
|
|
|
|
*pData.f = clamp(*pData.f, pData.min, pData.max);
|
|
|
|
pData.flags |= CVAR_MODIFIED;
|
2016-12-01 04:06:40 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (!OSD_ParsingScript())
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%s %f",pData.name, *pData.f);
|
2009-06-24 08:20:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-04-30 21:09:44 +00:00
|
|
|
case CVAR_DOUBLE:
|
2009-06-24 08:20:10 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (printValue)
|
2009-04-30 21:09:44 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("\"%s\" is \"%f\"\n%s: %s\n", pData.name, *pData.d, pData.name, pData.desc);
|
2009-06-24 08:20:10 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2009-04-30 21:09:44 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
Bsscanf(parm->parms[0], "%lf", pData.d);
|
|
|
|
*pData.d = clamp(*pData.d, pData.min, pData.max);
|
|
|
|
pData.flags |= CVAR_MODIFIED;
|
2016-12-01 04:06:40 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (!OSD_ParsingScript())
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%s %f",pData.name, *pData.d);
|
2009-06-24 08:20:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-04-30 21:09:44 +00:00
|
|
|
case CVAR_INT:
|
|
|
|
case CVAR_BOOL:
|
2009-06-24 08:20:10 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (printValue)
|
2009-04-30 01:07:08 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("\"%s\" is \"%d\"\n%s: %s\n", pData.name, *pData.i32, pData.name, pData.desc);
|
2009-06-24 08:20:10 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
*pData.i32 = clamp(Batoi(parm->parms[0]), pData.min, pData.max);
|
2009-04-29 06:20:07 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if ((pData.flags & CVAR_TYPEMASK) == CVAR_BOOL)
|
|
|
|
*pData.i32 = (*pData.i32 != 0);
|
2016-12-01 04:06:40 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
pData.flags |= CVAR_MODIFIED;
|
2016-12-01 04:06:40 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (!OSD_ParsingScript())
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%s %d",pData.name, *pData.i32);
|
2009-06-24 08:20:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-03-14 00:07:52 +00:00
|
|
|
case CVAR_UINT:
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (printValue)
|
2016-03-14 00:07:52 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("\"%s\" is \"%u\"\n%s: %s\n", pData.name, *pData.u32, pData.name, pData.desc);
|
2016-03-14 00:07:52 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
*pData.u32 = clamp(Bstrtoul(parm->parms[0], NULL, 0), pData.min, pData.max);
|
|
|
|
pData.flags |= CVAR_MODIFIED;
|
2016-03-14 00:07:52 +00:00
|
|
|
|
|
|
|
if (!OSD_ParsingScript())
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%s %d", pData.name, *pData.u32);
|
2016-03-14 00:07:52 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-04-30 21:09:44 +00:00
|
|
|
case CVAR_STRING:
|
2009-06-24 08:20:10 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
if (printValue)
|
2009-04-30 01:07:08 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("\"%s\" is \"%s\"\n%s: %s\n", pData.name, pData.string, pData.name, pData.desc);
|
2009-06-24 08:20:10 +00:00
|
|
|
return OSDCMD_OK;
|
2009-04-30 01:07:08 +00:00
|
|
|
}
|
2009-06-24 08:20:10 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
Bstrncpy(pData.string, parm->parms[0], pData.max-1);
|
|
|
|
(pData.string)[pData.max-1] = 0;
|
|
|
|
pData.flags |= CVAR_MODIFIED;
|
2016-12-01 04:06:40 +00:00
|
|
|
|
2009-06-24 08:20:10 +00:00
|
|
|
if (!OSD_ParsingScript())
|
2017-06-27 02:24:14 +00:00
|
|
|
OSD_Printf("%s %s",pData.name, pData.string);
|
2009-06-24 08:20:10 +00:00
|
|
|
}
|
|
|
|
break;
|
2009-04-30 21:09:44 +00:00
|
|
|
default:
|
2014-10-29 17:06:43 +00:00
|
|
|
EDUKE32_UNREACHABLE_SECTION(break);
|
2009-04-30 21:09:44 +00:00
|
|
|
}
|
2013-05-15 02:16:19 +00:00
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
|
|
|
if (!OSD_ParsingScript())
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
switch (pData.flags&(CVAR_RESTARTVID|CVAR_INVALIDATEALL|CVAR_INVALIDATEART))
|
2013-05-15 02:16:19 +00:00
|
|
|
{
|
|
|
|
case CVAR_RESTARTVID:
|
|
|
|
osdcmd_restartvid(NULL);
|
|
|
|
break;
|
2013-05-15 02:17:17 +00:00
|
|
|
case CVAR_INVALIDATEALL:
|
2013-05-15 02:20:08 +00:00
|
|
|
gltexinvalidatetype(INVALIDATE_ALL);
|
2017-07-18 20:53:41 +00:00
|
|
|
fallthrough__;
|
2013-05-15 02:17:17 +00:00
|
|
|
case CVAR_INVALIDATEART:
|
2013-05-15 02:20:08 +00:00
|
|
|
gltexinvalidatetype(INVALIDATE_ART);
|
2013-05-15 02:16:19 +00:00
|
|
|
#ifdef POLYMER
|
|
|
|
if (getrendermode() == REND_POLYMER)
|
|
|
|
polymer_texinvalidate();
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
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;
|
|
|
|
}
|
|
|
|
|
2013-12-24 09:44:24 +00:00
|
|
|
void OSD_WriteAliases(FILE *fp)
|
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
for (osdsymbol_t *symb=symbols; symb!=NULL; symb=symb->next)
|
2013-12-24 09:44:24 +00:00
|
|
|
if (symb->func == (void *)OSD_ALIAS)
|
|
|
|
Bfprintf(fp, "alias \"%s\" \"%s\"\n", symb->name, symb->help);
|
|
|
|
}
|
|
|
|
|
2009-04-30 21:09:44 +00:00
|
|
|
void OSD_WriteCvars(FILE *fp)
|
2009-04-29 19:43:51 +00:00
|
|
|
{
|
2010-05-02 23:27:30 +00:00
|
|
|
if (!fp)
|
|
|
|
return;
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
for (unsigned i = 0; i < osd->numcvars; i++)
|
2009-04-29 19:43:51 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
osdcvardata_t const &pData = *osd->cvars[i].pData;
|
|
|
|
|
|
|
|
if (!(pData.flags & CVAR_NOSAVE) && OSD_CvarModified(&osd->cvars[i]))
|
|
|
|
switch (pData.flags & CVAR_TYPEMASK)
|
2011-01-16 02:50:27 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
case CVAR_FLOAT: fprintf(fp, "%s \"%f\"\n", pData.name, *pData.f); break;
|
|
|
|
case CVAR_DOUBLE: fprintf(fp, "%s \"%f\"\n", pData.name, *pData.d); break;
|
2010-05-02 23:27:30 +00:00
|
|
|
case CVAR_INT:
|
2017-06-27 02:24:14 +00:00
|
|
|
case CVAR_BOOL: fprintf(fp, "%s \"%d\"\n", pData.name, *pData.i32); break;
|
|
|
|
case CVAR_UINT: fprintf(fp, "%s \"%u\"\n", pData.name, *pData.u32); break;
|
|
|
|
case CVAR_STRING: fprintf(fp, "%s \"%s\"\n", pData.name, pData.string); break;
|
|
|
|
default: EDUKE32_UNREACHABLE_SECTION(break);
|
2011-01-16 02:50:27 +00:00
|
|
|
}
|
2009-04-29 19:43:51 +00:00
|
|
|
}
|
|
|
|
}
|