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"
|
2008-06-30 07:30:48 +00:00
|
|
|
#include "cache1d.h"
|
2010-05-09 22:12:29 +00:00
|
|
|
#include "crc32.h"
|
2019-09-09 22:07:11 +00:00
|
|
|
#include "compat.h"
|
|
|
|
#include "baselayer.h"
|
2018-11-18 18:09:48 +00:00
|
|
|
#include "osd.h"
|
|
|
|
#include "scancodes.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"
|
2013-12-24 09:44:24 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
#include "vfs.h"
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
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
|
|
|
|
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
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
osdmain_t *osd;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:05:45 +00:00
|
|
|
static int osdrowscur = -1;
|
|
|
|
static int osdmaxrows = 20;
|
2018-11-18 18:06:21 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
buildvfs_FILE osdlog;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
const char *osdlogfn;
|
|
|
|
|
|
|
|
static uint32_t osdkeytime = 0;
|
|
|
|
static uint32_t osdscrtime = 0;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:05:37 +00:00
|
|
|
#define OSD_EDIT_LINE_WIDTH (osd->draw.cols - 1 - 3)
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:05:37 +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
|
|
|
|
2018-11-18 18:05:45 +00:00
|
|
|
static hashtable_t h_cvars = { OSDMAXSYMBOLS >> 1, NULL };
|
2018-11-18 18:05:10 +00:00
|
|
|
bool m32_osd_tryscript = false; // whether to try executing m32script on unkown command in the osd
|
2010-05-22 23:41:18 +00:00
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
void OSD_RegisterCvar(osdcvardata_t * const cvar, int (*func)(osdcmdptr_t))
|
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)))
|
2017-10-15 23:10:09 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
inBuf += 2 + !!isdigit(*(inBuf+2));
|
2017-10-15 23:10:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
else if ((Btoupper(*(inBuf+1)) == 'O'))
|
2017-10-15 23:10:09 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
inBuf += 2;
|
2017-10-15 23:10:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
else if ((Btoupper(*(inBuf+1)) == 'S') && isdigit(*(inBuf+2)))
|
2017-10-15 23:10:09 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
inBuf += 3;
|
2017-10-15 23:10:09 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-07-19 00:50:20 +00:00
|
|
|
}
|
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;
|
2019-03-01 08:51:50 +00:00
|
|
|
int32_t len = 0;
|
|
|
|
buildvfs_kfd handle;
|
2014-10-25 03:29:53 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
if ((handle = kopen4load(szScript, 0)) == buildvfs_kfd_invalid)
|
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
|
2008-06-30 07:30:48 +00:00
|
|
|
|
2018-11-18 18:06:01 +00:00
|
|
|
if (!err)
|
2014-10-25 03:35:05 +00:00
|
|
|
OSD_Printf("Executing \"%s\"\n", szScript);
|
|
|
|
|
2018-11-18 18:06:01 +00:00
|
|
|
auto buf = (char *) Xmalloc(len + 1);
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
if (err || kread(handle, buf, len) != len)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2018-11-18 18:07:20 +00:00
|
|
|
if (!err) // no error message for blank file
|
2014-10-25 03:29:53 +00:00
|
|
|
OSD_Printf("Error executing \"%s\"!\n", szScript);
|
2018-11-18 18:06:01 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
if (handle != buildvfs_kfd_invalid)
|
2018-11-18 18:06:01 +00:00
|
|
|
kclose(handle);
|
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(buf);
|
2014-10-25 03:29:53 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2008-06-30 07:30:48 +00:00
|
|
|
|
2017-12-02 08:44:59 +00:00
|
|
|
kclose(handle);
|
2018-11-18 18:06:01 +00:00
|
|
|
buf[len] = '\0';
|
2014-10-25 03:29:53 +00:00
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
char const *cp = strtok(buf, "\r\n");
|
2014-10-25 03:29:53 +00:00
|
|
|
|
2018-11-18 18:06:01 +00:00
|
|
|
++osd->execdepth;
|
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
|
|
|
}
|
2018-11-18 18:06:01 +00:00
|
|
|
--osd->execdepth;
|
2014-10-25 03:29:53 +00:00
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(buf);
|
2014-10-25 03:29:53 +00:00
|
|
|
return 0;
|
2008-06-30 07:30:48 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:05:45 +00:00
|
|
|
int OSD_ParsingScript(void) { return osd->execdepth; }
|
|
|
|
int OSD_OSDKey(void) { return osd->keycode; }
|
|
|
|
int OSD_GetCols(void) { return osd->draw.cols; }
|
|
|
|
int OSD_IsMoving(void) { return (osdrowscur != -1 && osdrowscur != osd->draw.rows); }
|
|
|
|
int OSD_GetRowsCur(void) { return osdrowscur; }
|
|
|
|
int OSD_GetTextMode(void) { return osd->draw.mode; }
|
2008-07-23 03:56:50 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
void OSD_GetShadePal(const char *ch, int *shd, int *pal)
|
2013-11-04 22:56:08 +00:00
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
auto &t = osd->text;
|
|
|
|
|
|
|
|
if (ch < t.buf || ch >= t.buf + OSDBUFFERSIZE)
|
2017-06-27 02:24:14 +00:00
|
|
|
return;
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
*shd = (t.fmt[ch-t.buf] & ~0x1F)>>4;
|
|
|
|
*pal = (t.fmt[ch-t.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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
void OSD_SetTextMode(int 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);
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_exec(osdcmdptr_t parm)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2015-07-08 03:34:37 +00:00
|
|
|
if (parm->numparms != 1)
|
|
|
|
return OSDCMD_SHOWHELP;
|
|
|
|
|
2018-11-18 18:06:01 +00:00
|
|
|
if (OSD_Exec(parm->parms[0]))
|
|
|
|
OSD_Printf("%sexec: file \"%s\" not found.\n", osd->draw.errorfmt, parm->parms[0]);
|
2015-07-08 03:34:37 +00:00
|
|
|
|
2008-06-30 07:30:48 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_echo(osdcmdptr_t 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;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_fileinfo(osdcmdptr_t parm)
|
2010-05-09 22:12:29 +00:00
|
|
|
{
|
|
|
|
if (parm->numparms != 1) return OSDCMD_SHOWHELP;
|
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
buildvfs_kfd h;
|
2018-11-18 18:05:51 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
if ((h = kopen4load(parm->parms[0],0)) == buildvfs_kfd_invalid)
|
2010-05-09 22:12:29 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("fileinfo: File \"%s\" not found.\n", parm->parms[0]);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:05:51 +00:00
|
|
|
int32_t crctime = timerGetTicks();
|
|
|
|
uint32_t crcval = 0;
|
|
|
|
int32_t siz = 0;
|
|
|
|
|
|
|
|
static constexpr int ReadSize = 65536;
|
2018-12-15 01:39:51 +00:00
|
|
|
auto buf = (uint8_t *)Xmalloc(ReadSize);
|
2018-11-18 18:05:51 +00:00
|
|
|
|
2010-05-09 22:12:29 +00:00
|
|
|
do
|
|
|
|
{
|
2018-11-18 18:05:51 +00:00
|
|
|
siz = kread(h, buf, ReadSize);
|
|
|
|
crcval = Bcrc32((uint8_t *)buf, siz, crcval);
|
2010-05-09 22:12:29 +00:00
|
|
|
}
|
2018-11-18 18:05:51 +00:00
|
|
|
while (siz == ReadSize);
|
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
crctime = timerGetTicks() - crctime;
|
2014-03-22 09:26:39 +00:00
|
|
|
|
2018-11-18 18:05:51 +00:00
|
|
|
klseek(h, 0, BSEEK_SET);
|
2014-03-22 09:26:39 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
int32_t xxhtime = timerGetTicks();
|
2018-11-18 18:05:51 +00:00
|
|
|
|
2017-06-14 07:00:02 +00:00
|
|
|
XXH32_state_t xxh;
|
|
|
|
XXH32_reset(&xxh, 0x1337);
|
2018-11-18 18:05:51 +00:00
|
|
|
|
2014-03-22 09:26:39 +00:00
|
|
|
do
|
|
|
|
{
|
2018-11-18 18:05:51 +00:00
|
|
|
siz = kread(h, buf, ReadSize);
|
|
|
|
XXH32_update(&xxh, (uint8_t *)buf, siz);
|
2014-03-22 09:26:39 +00:00
|
|
|
}
|
2018-11-18 18:05:51 +00:00
|
|
|
while (siz == ReadSize);
|
|
|
|
|
|
|
|
uint32_t const xxhash = XXH32_digest(&xxh);
|
2018-04-12 21:02:51 +00:00
|
|
|
xxhtime = timerGetTicks() - xxhtime;
|
2010-05-09 22:12:29 +00:00
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(buf);
|
2010-05-09 22:12:29 +00:00
|
|
|
|
|
|
|
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",
|
2018-11-18 18:05:51 +00:00
|
|
|
parm->parms[0], kfilelength(h),
|
2019-08-13 14:44:16 +00:00
|
|
|
crcval, (double)crctime/timerGetRate(),
|
|
|
|
xxhash, (double)xxhtime/timerGetRate());
|
2010-05-09 22:12:29 +00:00
|
|
|
|
2018-11-18 18:05:51 +00:00
|
|
|
kclose(h);
|
|
|
|
|
2010-05-09 22:12:29 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
static void _internal_drawosdchar(int x, int y, char ch, int shade, int 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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
static void _internal_drawosdstr(int x, int y, const char *ch, int len, int shade, int 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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
static void _internal_drawosdcursor(int x, int y, int flags, int 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
|
|
|
// 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.)
|
2018-11-18 18:06:27 +00:00
|
|
|
for (int i=0, k=UINT8_MAX+1; i<256; i++)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
int const j =
|
2017-06-27 02:24:14 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
static int _internal_getcolumnwidth(int 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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
static int _internal_getrowheight(int 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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
static void _internal_clearbackground(int cols, int 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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
static void _internal_onshowosd(int 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
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_alias(osdcmdptr_t parm)
|
2008-06-29 22:37:30 +00:00
|
|
|
{
|
|
|
|
if (parm->numparms < 1)
|
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
int cnt = 0;
|
|
|
|
|
2008-06-29 22:37:30 +00:00
|
|
|
OSD_Printf("Alias listing:\n");
|
2018-11-18 18:06:21 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
for (auto &symb : osd->symbptrs)
|
2018-11-18 18:06:21 +00:00
|
|
|
{
|
2018-11-18 18:07:20 +00:00
|
|
|
if (symb == NULL)
|
2018-11-18 18:06:21 +00:00
|
|
|
break;
|
2018-11-18 18:06:27 +00:00
|
|
|
else if (symb->func == OSD_ALIAS)
|
2008-07-02 22:45:04 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
cnt++;
|
2018-11-18 18:06:27 +00:00
|
|
|
OSD_Printf(" %s \"%s\"\n", symb->name, symb->help);
|
2008-07-02 22:45:04 +00:00
|
|
|
}
|
2018-11-18 18:06:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cnt == 0)
|
2008-07-02 22:45:04 +00:00
|
|
|
OSD_Printf("No aliases found.\n");
|
2018-11-18 18:06:21 +00:00
|
|
|
|
2008-06-29 22:37:30 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
for (auto &symb : osd->symbptrs)
|
2008-06-29 22:37:30 +00:00
|
|
|
{
|
2018-11-18 18:07:20 +00:00
|
|
|
if (symb == NULL)
|
2018-11-18 18:06:21 +00:00
|
|
|
break;
|
2018-11-18 18:06:27 +00:00
|
|
|
else if (!Bstrcasecmp(parm->parms[0], symb->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
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
if (symb->func == OSD_ALIAS)
|
|
|
|
OSD_Printf("alias %s \"%s\"\n", symb->name, symb->help);
|
2018-11-18 18:06:21 +00:00
|
|
|
else
|
2018-11-18 18:06:27 +00:00
|
|
|
OSD_Printf("%s is not an alias\n", symb->name);
|
2018-11-18 18:06:21 +00:00
|
|
|
|
2008-06-30 00:32:05 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2018-11-18 18:06:27 +00:00
|
|
|
else if (symb->func != OSD_ALIAS && symb->func != OSD_UNALIASED)
|
2008-06-30 00:32:05 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
OSD_Printf("Cannot override a function or cvar with an alias\n");
|
|
|
|
|
2008-06-30 00:32:05 +00:00
|
|
|
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)
|
2018-11-18 18:06:21 +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;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_unalias(osdcmdptr_t parm)
|
2008-06-30 01:03:51 +00:00
|
|
|
{
|
|
|
|
if (parm->numparms < 1)
|
|
|
|
return OSDCMD_SHOWHELP;
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
for (auto symb=osd->symbols; symb!=NULL; symb=symb->next)
|
2008-06-30 01:03:51 +00:00
|
|
|
{
|
2018-11-18 18:05:37 +00:00
|
|
|
if (!Bstrcasecmp(parm->parms[0], symb->name))
|
2008-06-30 01:03:51 +00:00
|
|
|
{
|
|
|
|
if (parm->numparms < 2)
|
|
|
|
{
|
2018-11-18 18:05:37 +00:00
|
|
|
if (symb->func == OSD_ALIAS)
|
2008-06-30 01:03:51 +00:00
|
|
|
{
|
2018-11-18 18:05:37 +00:00
|
|
|
OSD_Printf("Removed alias %s (\"%s\")\n", symb->name, symb->help);
|
|
|
|
symb->func = OSD_UNALIASED;
|
2008-06-30 01:03:51 +00:00
|
|
|
}
|
2018-11-18 18:05:37 +00:00
|
|
|
else
|
|
|
|
OSD_Printf("Invalid alias %s\n", symb->name);
|
|
|
|
|
2008-06-30 01:03:51 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-18 18:05:37 +00:00
|
|
|
|
|
|
|
OSD_Printf("Invalid alias %s\n", parm->parms[0]);
|
2008-06-30 01:03:51 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_listsymbols(osdcmdptr_t parm)
|
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
|
|
|
|
2018-11-18 18:05:37 +00:00
|
|
|
int maxwidth = 0;
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
for (auto symb=osd->symbols; symb!=NULL; symb=symb->next)
|
2019-03-20 11:24:25 +00:00
|
|
|
if (symb->func != OSD_UNALIASED && symb->help != NULL)
|
2018-11-18 18:05:37 +00:00
|
|
|
maxwidth = max<int>(maxwidth, Bstrlen(symb->name));
|
2008-06-30 07:30:48 +00:00
|
|
|
|
|
|
|
if (maxwidth > 0)
|
|
|
|
{
|
2018-11-18 18:05:37 +00:00
|
|
|
int width = 0;
|
|
|
|
int 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
|
|
|
|
2018-11-18 18:05:32 +00:00
|
|
|
int const parmlen = parm->numparms ? Bstrlen(parm->parms[0]) : 0;
|
2018-10-07 05:22:03 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
for (auto symb=osd->symbols; symb!=NULL; symb=symb->next)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2019-03-20 11:24:25 +00:00
|
|
|
if (symb->func == OSD_UNALIASED || symb->help == NULL || (parm->numparms == 1 && Bstrncmp(parm->parms[0], symb->name, parmlen)))
|
2011-04-07 01:16:29 +00:00
|
|
|
continue;
|
|
|
|
|
2018-11-18 18:05:37 +00:00
|
|
|
int const var = hash_find(&h_cvars, symb->name);
|
2010-06-07 09:03:16 +00:00
|
|
|
|
2019-05-19 03:56:13 +00:00
|
|
|
if ((unsigned)var < OSDMAXSYMBOLS && OSD_CvarModified(&osd->cvars[var]))
|
2018-11-18 18:05:32 +00:00
|
|
|
{
|
|
|
|
OSD_Printf("%s*", osd->draw.highlight);
|
2018-11-18 18:05:37 +00:00
|
|
|
OSD_Printf("%-*s", maxwidth-1, symb->name);
|
2008-06-30 07:30:48 +00:00
|
|
|
}
|
2018-11-18 18:05:37 +00:00
|
|
|
else
|
|
|
|
OSD_Printf("%-*s", maxwidth, symb->name);
|
2018-11-18 18:05:32 +00:00
|
|
|
|
2018-11-18 18:05:37 +00:00
|
|
|
width += maxwidth;
|
2018-11-18 18:05:32 +00:00
|
|
|
count++;
|
2011-04-07 01:16:29 +00:00
|
|
|
|
2018-11-18 18:05:37 +00:00
|
|
|
if (width > osd->draw.cols - maxwidth)
|
2008-06-30 07:30:48 +00:00
|
|
|
{
|
2018-11-18 18:05:37 +00:00
|
|
|
width = 0;
|
2008-06-30 07:30:48 +00:00
|
|
|
OSD_Printf("\n");
|
|
|
|
}
|
|
|
|
}
|
2018-11-18 18:05:37 +00:00
|
|
|
|
|
|
|
if (width)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_help(osdcmdptr_t parm)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2014-07-06 00:12:25 +00:00
|
|
|
if (parm->numparms != 1)
|
|
|
|
return OSDCMD_SHOWHELP;
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
auto 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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_clear(osdcmdptr_t UNUSED(parm))
|
2007-01-04 07:15:17 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
UNREFERENCED_CONST_PARAMETER(parm);
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
auto &t = osd->text;
|
|
|
|
|
|
|
|
Bmemset(t.buf, 0, OSDBUFFERSIZE);
|
|
|
|
Bmemset(t.fmt, osd->draw.textpal + (osd->draw.textshade<<5), OSDBUFFERSIZE);
|
|
|
|
t.lines = 1;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2007-01-04 07:15:17 +00:00
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_history(osdcmdptr_t UNUSED(parm))
|
2008-07-07 12:17:27 +00:00
|
|
|
{
|
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
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
auto &h = osd->history;
|
|
|
|
|
|
|
|
for (int i=osd->history.maxlines-1, j=0; i>=0; i--)
|
|
|
|
{
|
|
|
|
if (h.buf[i])
|
|
|
|
OSD_Printf("%4d \"%s\"\n", h.total - h.lines + (++j), h.buf[i]);
|
|
|
|
}
|
2014-07-06 00:12:25 +00:00
|
|
|
|
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
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
for (auto &symb : osd->symbptrs)
|
|
|
|
DO_FREE_AND_NULL(symb);
|
2018-11-18 18:06:21 +00:00
|
|
|
|
|
|
|
osd->symbols = NULL;
|
|
|
|
|
|
|
|
for (auto & i : osd->history.buf)
|
|
|
|
DO_FREE_AND_NULL(i);
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
DO_FREE_AND_NULL(osd->cvars);
|
2018-11-18 18:06:21 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
DO_FREE_AND_NULL(osd->editor.buf);
|
2015-05-25 12:57:49 +00:00
|
|
|
DO_FREE_AND_NULL(osd->editor.tmp);
|
2018-11-18 18:06:21 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
DO_FREE_AND_NULL(osd->text.buf);
|
|
|
|
DO_FREE_AND_NULL(osd->text.fmt);
|
2018-11-18 18:06:21 +00:00
|
|
|
|
2017-12-02 12:42:36 +00:00
|
|
|
DO_FREE_AND_NULL(osd->version.buf);
|
2018-11-18 18:06:21 +00:00
|
|
|
|
|
|
|
MAYBE_FCLOSE_AND_NULL(osdlog);
|
2014-07-06 00:12:25 +00:00
|
|
|
DO_FREE_AND_NULL(osd);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdcmd_cvar_set_osd(osdcmdptr_t parm)
|
2009-04-30 01:07:08 +00:00
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
int const r = osdcmd_cvar_set(parm);
|
2009-04-30 01:07:08 +00:00
|
|
|
|
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;
|
2018-11-18 18:06:07 +00:00
|
|
|
|
2015-07-08 03:34:37 +00:00
|
|
|
if (osdrowscur != -1)
|
|
|
|
osdrowscur = osd->draw.rows;
|
|
|
|
}
|
|
|
|
else if (!Bstrcasecmp(parm->name, "osdtextmode"))
|
|
|
|
OSD_SetTextMode(osd->draw.mode);
|
|
|
|
else if (!Bstrcasecmp(parm->name, "osdhistorydepth"))
|
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
for (auto &i : osd->history.buf)
|
|
|
|
DO_FREE_AND_NULL(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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
static int osdfunc_toggle(osdcmdptr_t parm)
|
2010-06-07 09:03:16 +00:00
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
if (parm->numparms != 1)
|
|
|
|
return OSDCMD_SHOWHELP;
|
2010-06-07 09:03:16 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
int i = hash_find(&h_cvars, parm->parms[0]);
|
2010-06-07 09:03:16 +00:00
|
|
|
|
|
|
|
if (i == -1)
|
2018-11-18 18:06:21 +00:00
|
|
|
{
|
|
|
|
for (i = osd->numcvars-1; i>=0; i--)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2018-10-25 23:28:56 +00:00
|
|
|
osd = (osdmain_t *)Xcalloc(1, sizeof(osdmain_t));
|
2014-07-06 00:12:25 +00:00
|
|
|
|
|
|
|
mutex_init(&osd->mutex);
|
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
if (!osd->keycode)
|
|
|
|
osd->keycode = sc_Tilde;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-10-25 23:28:56 +00:00
|
|
|
osd->text.buf = (char *)Xmalloc(OSDBUFFERSIZE);
|
|
|
|
osd->text.fmt = (char *)Xmalloc(OSDBUFFERSIZE);
|
|
|
|
osd->editor.buf = (char *)Xmalloc(OSDEDITLENGTH);
|
|
|
|
osd->editor.tmp = (char *)Xmalloc(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));
|
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
osd->numsymbols = 0;
|
|
|
|
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;
|
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
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 },
|
|
|
|
};
|
|
|
|
|
2018-10-25 23:33:40 +00:00
|
|
|
for (auto & i : cvars_osd)
|
|
|
|
OSD_RegisterCvar(&i, (i.flags & CVAR_FUNCPTR) ? osdcmd_cvar_set_osd : osdcmd_cvar_set);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
2019-03-11 06:06:47 +00:00
|
|
|
osdlog = buildvfs_fopen_write_text(fn);
|
2014-10-25 03:29:53 +00:00
|
|
|
|
|
|
|
if (osdlog)
|
2014-12-17 13:02:21 +00:00
|
|
|
{
|
2019-03-01 08:51:50 +00:00
|
|
|
#ifndef USE_PHYSFS
|
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);
|
2019-03-01 08:51:50 +00:00
|
|
|
#endif
|
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
|
|
|
|
//
|
2018-11-18 18:06:27 +00:00
|
|
|
void OSD_SetFunctions(void (*drawchar)(int, int, char, int, int),
|
|
|
|
void (*drawstr)(int, int, const char *, int, int, int),
|
|
|
|
void (*drawcursor)(int, int, int, int),
|
|
|
|
int (*colwidth)(int),
|
|
|
|
int (*rowheight)(int),
|
|
|
|
void (*clearbg)(int, int),
|
2017-06-27 02:24:14 +00:00
|
|
|
int32_t (*gtime)(void),
|
2018-11-18 18:06:27 +00:00
|
|
|
void (*showosd)(int))
|
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
|
|
|
|
//
|
2018-11-18 18:06:27 +00:00
|
|
|
void OSD_SetParameters(int promptShade, int promptPal, int editShade, int editPal, int textShade, int textPal,
|
|
|
|
char const *errorStr, char 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
|
|
|
|
//
|
2018-11-18 18:05:45 +00:00
|
|
|
static int OSD_FindDiffPoint(const char *str1, const char *str2)
|
2008-07-01 11:14:18 +00:00
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
int 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;
|
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
static void OSD_AdjustEditorPosition(osdedit_t &e)
|
2008-07-08 04:52:39 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
e.pos = 0;
|
|
|
|
while (e.buf[e.pos])
|
|
|
|
e.pos++;
|
|
|
|
e.len = e.pos;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (e.pos < e.start)
|
2008-07-08 04:52:39 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
e.end = e.pos;
|
|
|
|
e.start = e.end - OSD_EDIT_LINE_WIDTH;
|
2008-07-08 04:52:39 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (e.start < 0)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
e.end -= e.start;
|
|
|
|
e.start = 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
}
|
2018-11-18 18:06:21 +00:00
|
|
|
else if (e.pos >= e.end)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
e.start += (e.pos - e.end);
|
|
|
|
e.end += (e.pos - e.end);
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
static void OSD_HistoryPrev(void)
|
2008-07-08 04:52:39 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
osdhist_t &h = osd->history;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
if (h.pos >= h.lines - 1)
|
|
|
|
return;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
osdedit_t &e = osd->editor;
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
Bmemcpy(e.buf, h.buf[++h.pos], OSDEDITLENGTH);
|
|
|
|
|
|
|
|
OSD_AdjustEditorPosition(e);
|
|
|
|
}
|
2008-07-08 04:52:39 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
static void OSD_HistoryNext(void)
|
|
|
|
{
|
|
|
|
osdhist_t &h = osd->history;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
if (h.pos < 0)
|
|
|
|
return;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
osdedit_t &e = osd->editor;
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (h.pos == 0)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
e.len = 0;
|
|
|
|
e.pos = 0;
|
|
|
|
e.start = 0;
|
|
|
|
e.end = OSD_EDIT_LINE_WIDTH;
|
|
|
|
h.pos = -1;
|
2018-11-18 18:06:27 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
return;
|
2010-05-02 23:27:30 +00:00
|
|
|
}
|
2018-11-18 18:06:21 +00:00
|
|
|
|
|
|
|
Bmemcpy(e.buf, h.buf[--h.pos], OSDEDITLENGTH);
|
|
|
|
|
|
|
|
OSD_AdjustEditorPosition(e);
|
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.
|
|
|
|
//
|
|
|
|
|
2018-11-18 18:05:45 +00:00
|
|
|
int 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
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
osdhist_t &h = osd->history;
|
|
|
|
osdedit_t &ed = osd->editor;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
|
|
|
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
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.pos = 0;
|
|
|
|
ed.start = 0;
|
|
|
|
ed.end = OSD_EDIT_LINE_WIDTH;
|
2017-06-27 02:24:14 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_B: // move one character left
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos > 0)
|
2018-11-18 18:06:27 +00:00
|
|
|
--ed.pos;
|
2017-06-27 02:24:14 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_C: // discard line
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.buf[ed.len] = 0;
|
|
|
|
OSD_Printf("%s\n", ed.buf);
|
|
|
|
|
|
|
|
ed.len = 0;
|
|
|
|
ed.pos = 0;
|
|
|
|
ed.start = 0;
|
|
|
|
ed.end = OSD_EDIT_LINE_WIDTH;
|
|
|
|
ed.buf[0] = 0;
|
2017-06-27 02:24:14 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_E: // jump to end of line
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.pos = ed.len;
|
|
|
|
ed.end = ed.pos;
|
|
|
|
ed.start = ed.end - OSD_EDIT_LINE_WIDTH;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.start < 0)
|
2017-06-27 02:24:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.start = 0;
|
|
|
|
ed.end = OSD_EDIT_LINE_WIDTH;
|
2017-06-27 02:24:14 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case asc_Ctrl_F: // move one character right
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos < ed.len)
|
|
|
|
ed.pos++;
|
2017-06-27 02:24:14 +00:00
|
|
|
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
|
2018-11-18 18:06:21 +00:00
|
|
|
if (!ed.pos || !ed.len)
|
2017-06-27 02:24:14 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((osd->flags & OSD_OVERTYPE) == 0)
|
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos < ed.len)
|
|
|
|
Bmemmove(ed.buf + ed.pos - 1, ed.buf + ed.pos, ed.len - ed.pos);
|
|
|
|
ed.len--;
|
2017-06-27 02:24:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (--ed.pos < ed.start)
|
|
|
|
ed.start--, ed.end--;
|
2011-06-17 11:53:41 +00:00
|
|
|
#ifndef __APPLE__
|
2017-07-30 05:42:01 +00:00
|
|
|
fallthrough__;
|
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
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
int commonsize = INT_MAX;
|
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;
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
for (editPos = ed.pos; editPos > 0; editPos--)
|
|
|
|
if (ed.buf[editPos - 1] == ' ')
|
2017-06-27 02:24:14 +00:00
|
|
|
break;
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
for (iter = 0; editPos < ed.len && ed.buf[editPos] != ' '; iter++, editPos++)
|
|
|
|
ed.tmp[iter] = ed.buf[editPos];
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.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
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
tabc = osd_findsymbol(ed.tmp, NULL);
|
2008-07-09 09:34:12 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (tabc && tabc->next && osd_findsymbol(ed.tmp, tabc->next))
|
2006-12-11 03:06:49 +00:00
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
auto symb = tabc;
|
|
|
|
int 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;
|
|
|
|
}
|
|
|
|
|
2018-10-16 06:09:54 +00:00
|
|
|
maxwidth = max<int>(maxwidth, Bstrlen(symb->name));
|
2017-06-27 02:24:14 +00:00
|
|
|
lastmatch = symb;
|
|
|
|
|
|
|
|
if (!lastmatch->next)
|
|
|
|
break;
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
symb = osd_findsymbol(ed.tmp, lastmatch->next);
|
2008-07-09 09:34:12 +00:00
|
|
|
}
|
2011-01-16 02:50:27 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
OSD_Printf("%sFound %d possible completions for \"%s\":\n", osd->draw.highlight, num, ed.tmp);
|
2017-06-27 02:24:14 +00:00
|
|
|
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;
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
symb = osd_findsymbol(ed.tmp, lastmatch->next);
|
2017-06-27 02:24:14 +00:00
|
|
|
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
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
tabc = osd_findsymbol(ed.tmp, lastmatch->next);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-10-25 23:29:38 +00:00
|
|
|
if (!tabc)
|
2018-11-18 18:06:21 +00:00
|
|
|
tabc = osd_findsymbol(ed.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;
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
for (editPos = ed.pos; editPos > 0; editPos--)
|
|
|
|
if (ed.buf[editPos - 1] == ' ')
|
2017-06-27 02:24:14 +00:00
|
|
|
break;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.len = editPos;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
for (int iter = 0; tabc->name[iter] && ed.len <= OSDEDITLENGTH - 1 && (ed.len < commonsize); editPos++, iter++, ed.len++)
|
|
|
|
ed.buf[editPos] = tabc->name[iter];
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.pos = ed.len;
|
|
|
|
ed.end = ed.pos;
|
|
|
|
ed.start = ed.end - OSD_EDIT_LINE_WIDTH;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.start < 0)
|
2017-06-27 02:24:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.start = 0;
|
|
|
|
ed.end = OSD_EDIT_LINE_WIDTH;
|
2017-06-27 02:24:14 +00:00
|
|
|
}
|
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
|
2018-11-18 18:06:21 +00:00
|
|
|
Bmemset(ed.buf + ed.pos, 0, OSDEDITLENGTH - ed.pos);
|
|
|
|
ed.len = ed.pos;
|
2017-06-27 02:24:14 +00:00
|
|
|
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
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.len > 0)
|
2008-07-07 12:17:27 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.buf[ed.len] = 0;
|
|
|
|
if (!h.buf[0] || Bstrcmp(h.buf[0], ed.buf))
|
2017-06-27 02:24:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
DO_FREE_AND_NULL(h.buf[h.maxlines - 1]);
|
|
|
|
Bmemmove(&h.buf[1], &h.buf[0], sizeof(intptr_t) * h.maxlines - 1);
|
|
|
|
OSD_SetHistory(0, ed.buf);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (h.lines < h.maxlines)
|
|
|
|
h.lines++;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
h.total++;
|
2017-06-27 02:24:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (h.exec++ == h.maxlines)
|
|
|
|
OSD_Printf("Buffer full! Consider increasing \"osdhistorydepth\" beyond %d.\n", --h.exec);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
h.pos = -1;
|
2008-07-07 12:17:27 +00:00
|
|
|
}
|
2008-07-04 02:13:48 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.len = 0;
|
|
|
|
ed.pos = 0;
|
|
|
|
ed.start = 0;
|
|
|
|
ed.end = OSD_EDIT_LINE_WIDTH;
|
2017-06-27 02:24:14 +00:00
|
|
|
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
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos > 0 && ed.len)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos < ed.len)
|
|
|
|
Bmemmove(ed.buf, ed.buf + ed.pos, ed.len - ed.pos);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.len -= ed.pos;
|
|
|
|
ed.pos = 0;
|
|
|
|
ed.start = 0;
|
|
|
|
ed.end = OSD_EDIT_LINE_WIDTH;
|
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
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos > 0 && ed.len > 0)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
int editPos = ed.pos;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
while (editPos > 0 && ed.buf[editPos - 1] == asc_Space) editPos--;
|
|
|
|
while (editPos > 0 && ed.buf[editPos - 1] != asc_Space) editPos--;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos < ed.len)
|
|
|
|
Bmemmove(ed.buf + editPos, ed.buf + ed.pos, ed.len - ed.pos);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.len -= (ed.pos - editPos);
|
|
|
|
ed.pos = editPos;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos < ed.start)
|
2017-06-27 02:24:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.start = ed.pos;
|
|
|
|
ed.end = ed.start + OSD_EDIT_LINE_WIDTH;
|
2017-06-27 02:24:14 +00:00
|
|
|
}
|
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)
|
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.len == OSDEDITLENGTH) // buffer full, can't insert another char
|
2017-06-27 02:24:14 +00:00
|
|
|
return 0;
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos < ed.len)
|
|
|
|
Bmemmove(ed.buf + ed.pos + 1, ed.buf + ed.pos, ed.len - ed.pos);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.len++;
|
2017-06-27 02:24:14 +00:00
|
|
|
}
|
2018-11-18 18:06:21 +00:00
|
|
|
else if (ed.pos == ed.len)
|
|
|
|
ed.len++;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.buf[ed.pos++] = ch;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos > ed.end)
|
|
|
|
ed.start++, ed.end++;
|
2017-06-27 02:24:14 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
osddraw_t &draw = osd->draw;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
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
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
draw.scrolling = (osdrowscur == -1) ? 1 : (osdrowscur == draw.rows) ? -1 : -draw.scrolling;
|
2017-06-27 02:24:14 +00:00
|
|
|
osdrowscur += draw.scrolling;
|
|
|
|
OSD_CaptureInput(draw.scrolling == 1);
|
2018-04-12 21:02:51 +00:00
|
|
|
osdscrtime = timerGetTicks();
|
2008-07-02 01:32:53 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
osdedit_t &ed = osd->editor;
|
|
|
|
osdkeytime = 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);
|
2018-04-12 21:02:51 +00:00
|
|
|
osdscrtime = timerGetTicks();
|
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)
|
2018-11-18 18:06:27 +00:00
|
|
|
++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)
|
2018-11-18 18:06:27 +00:00
|
|
|
--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
|
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.pos = 0;
|
|
|
|
ed.start = ed.pos;
|
|
|
|
ed.end = ed.start + OSD_EDIT_LINE_WIDTH;
|
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
|
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.pos = ed.len;
|
|
|
|
ed.end = ed.pos;
|
|
|
|
ed.start = ed.end - OSD_EDIT_LINE_WIDTH;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.start < 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.start = 0;
|
|
|
|
ed.end = OSD_EDIT_LINE_WIDTH;
|
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:
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.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
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
while (ed.pos > 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.buf[ed.pos-1] != asc_Space)
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
--ed.pos;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
while (ed.pos > 0)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.buf[ed.pos-1] == asc_Space)
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
--ed.pos;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2018-11-18 18:06:27 +00:00
|
|
|
else --ed.pos;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos < ed.start)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.end -= (ed.start - ed.pos);
|
|
|
|
ed.start -= (ed.start - ed.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:
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos < ed.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
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
while (ed.pos < ed.len)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.buf[ed.pos] == asc_Space)
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.pos++;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
while (ed.pos < ed.len)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.buf[ed.pos] != asc_Space)
|
2010-05-02 23:27:30 +00:00
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.pos++;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
2018-11-18 18:06:21 +00:00
|
|
|
else ed.pos++;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos >= ed.end)
|
2010-05-02 23:27:30 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.start += (ed.pos - ed.end);
|
|
|
|
ed.end += (ed.pos - ed.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:
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos == ed.len || !ed.len)
|
2010-05-02 23:27:30 +00:00
|
|
|
return 0;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (ed.pos <= ed.len-1)
|
|
|
|
Bmemmove(ed.buf+ed.pos, ed.buf+ed.pos+1, ed.len-ed.pos-1);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
ed.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
|
|
|
//
|
2018-11-18 18:06:27 +00:00
|
|
|
void OSD_ResizeDisplay(int w, int h)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
auto &t = osd->text;
|
|
|
|
auto &d = osd->draw;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
int const newcols = getcolumnwidth(w);
|
|
|
|
int const newmaxlines = OSDBUFFERSIZE / newcols;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
auto newtext = (char *)Xmalloc(OSDBUFFERSIZE);
|
|
|
|
auto newfmt = (char *)Xmalloc(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
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
int const copylines = min(newmaxlines, t.maxlines);
|
|
|
|
int const copycols = min(newcols, d.cols);
|
|
|
|
|
|
|
|
for (int i = 0; i < copylines; ++i)
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
Bmemcpy(newtext + newcols * i, t.buf + d.cols * i, copycols);
|
|
|
|
Bmemcpy(newfmt + newcols * i, t.fmt + d.cols * i, copycols);
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(t.buf);
|
2018-11-18 18:06:27 +00:00
|
|
|
t.buf = newtext;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(t.fmt);
|
2018-11-18 18:06:27 +00:00
|
|
|
t.fmt = newfmt;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
t.maxlines = newmaxlines;
|
|
|
|
osdmaxrows = getrowheight(h) - 2;
|
|
|
|
d.cols = newcols;
|
2014-07-06 00:12:25 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
if (d.rows > osdmaxrows)
|
|
|
|
d.rows = osdmaxrows;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
t.pos = 0;
|
|
|
|
d.head = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2014-07-06 00:12:25 +00:00
|
|
|
osd->editor.start = 0;
|
2018-11-18 18:06:27 +00:00
|
|
|
osd->editor.end = OSD_EDIT_LINE_WIDTH;
|
|
|
|
|
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
|
|
|
//
|
2018-11-18 18:06:27 +00:00
|
|
|
void OSD_CaptureInput(int 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
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
mouseGrabInput(cap == 0 ? g_mouseLockedToWindow : 0);
|
2010-05-02 23:27:30 +00:00
|
|
|
onshowosd(cap);
|
|
|
|
|
2018-04-12 21:02:31 +00:00
|
|
|
keyFlushChars();
|
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
|
|
|
|
//
|
2018-11-18 18:06:27 +00:00
|
|
|
void OSD_ShowDisplay(int 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)
|
|
|
|
{
|
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)
|
2018-11-18 18:06:21 +00:00
|
|
|
OSD_ShowDisplay((osd->flags & OSD_DRAW) != OSD_DRAW);
|
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
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
uint32_t j = (timerGetTicks() - osdscrtime);
|
|
|
|
|
|
|
|
while (j < UINT32_MAX)
|
2007-01-06 09:50:02 +00:00
|
|
|
{
|
2014-10-25 03:29:21 +00:00
|
|
|
j -= tabledivide32_noinline(200, osd->draw.rows);
|
2018-11-18 18:06:27 +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
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
uint32_t j = (timerGetTicks() - osdscrtime);
|
|
|
|
|
|
|
|
while (j < UINT32_MAX)
|
2007-01-06 09:50:02 +00:00
|
|
|
{
|
2014-10-25 03:29:21 +00:00
|
|
|
j -= tabledivide32_noinline(200, osd->draw.rows);
|
2018-11-18 18:06:27 +00:00
|
|
|
if (--osdrowscur < 1)
|
2007-01-06 09:50:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
osdscrtime = timerGetTicks();
|
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
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
int topoffs = osd->draw.head * osd->draw.cols;
|
|
|
|
int row = osdrowscur - 1;
|
|
|
|
int lines = min(osd->text.lines - osd->draw.head, osdrowscur);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
videoBeginDrawing();
|
2006-04-24 19:04:22 +00:00
|
|
|
|
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;
|
2018-11-18 18:06:21 +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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
int offset = ((osd->flags & (OSD_CAPS | OSD_SHIFT)) == (OSD_CAPS | OSD_SHIFT) && osd->draw.head > 0);
|
2019-08-27 13:39:54 +00:00
|
|
|
int const shade = osd->draw.promptshade ? osd->draw.promptshade : (sintable[((int32_t) totalclock<<4)&2047]>>11);
|
2008-10-11 09:20:04 +00:00
|
|
|
|
2018-11-18 18:06:21 +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);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (osd->flags & OSD_CAPS)
|
|
|
|
drawosdchar((osd->draw.head > 0), osdrowscur, 'C', shade, osd->draw.promptpal);
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (osd->flags & OSD_SHIFT)
|
|
|
|
drawosdchar(1 + (osd->flags & OSD_CAPS && osd->draw.head > 0), osdrowscur, 'H', shade, osd->draw.promptpal);
|
2008-10-11 09:20:04 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
drawosdchar(2 + offset, osdrowscur, '>', shade, osd->draw.promptpal);
|
2010-05-25 10:56:00 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
int const len = min(osd->draw.cols-1-3 - offset, osd->editor.len - osd->editor.start);
|
2010-05-25 10:56:00 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
for (int x=len-1; x>=0; x--)
|
|
|
|
drawosdchar(3 + x + offset, osdrowscur, osd->editor.buf[osd->editor.start+x], osd->draw.editshade<<1, osd->draw.editpal);
|
|
|
|
|
|
|
|
offset += 3 + osd->editor.pos - osd->editor.start;
|
|
|
|
|
|
|
|
drawosdcursor(offset,osdrowscur,osd->flags & OSD_OVERTYPE,osdkeytime);
|
|
|
|
|
|
|
|
if (osd->version.buf)
|
|
|
|
drawosdstr(osd->draw.cols - osd->version.len, osdrowscur - (offset >= osd->draw.cols - osd->version.len),
|
2019-08-27 13:39:54 +00:00
|
|
|
osd->version.buf, osd->version.len, (sintable[((int32_t) totalclock<<4)&2047]>>11), osd->version.pal);
|
2007-12-12 17:42:14 +00:00
|
|
|
|
2018-04-12 21:02:51 +00:00
|
|
|
videoEndDrawing();
|
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
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
auto &t = osd->text;
|
|
|
|
auto &d = osd->draw;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
Bmemmove(t.buf + d.cols, t.buf, OSDBUFFERSIZE - d.cols);
|
|
|
|
Bmemset(t.buf, asc_Space, d.cols);
|
|
|
|
|
|
|
|
Bmemmove(t.fmt + d.cols, t.fmt, OSDBUFFERSIZE - d.cols);
|
|
|
|
Bmemset(t.fmt, d.textpal, d.cols);
|
|
|
|
|
|
|
|
if (t.lines < t.maxlines)
|
|
|
|
t.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
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
if (tmpstr[0] == 0)
|
|
|
|
return;
|
|
|
|
|
2018-04-12 21:03:30 +00:00
|
|
|
if (!osd)
|
|
|
|
OSD_Init();
|
|
|
|
|
2014-07-24 14:01:44 +00:00
|
|
|
const char *chp;
|
2018-11-18 18:06:07 +00:00
|
|
|
|
2018-11-18 18:06:27 +00:00
|
|
|
int textPal = osd->draw.textpal;
|
|
|
|
int 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
|
|
|
{
|
2018-10-25 23:29:38 +00:00
|
|
|
char *chp2 = Xstrdup(tmpstr);
|
2019-03-01 08:51:50 +00:00
|
|
|
buildvfs_fputs(OSD_StripColors(chp2, tmpstr), osdlog);
|
2018-10-25 23:29:38 +00:00
|
|
|
Bprintf("%s", chp2);
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(chp2);
|
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
|
|
|
{
|
2019-03-01 08:51:50 +00:00
|
|
|
buildvfs_fputs("\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')
|
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
osd->text.pos = 0;
|
|
|
|
++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')
|
|
|
|
{
|
2018-11-18 18:06:27 +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++;
|
2018-11-18 18:06:27 +00:00
|
|
|
textPal = osd->draw.textpal;
|
2017-06-27 02:24:14 +00:00
|
|
|
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)
|
|
|
|
{
|
2018-11-18 18:07:44 +00:00
|
|
|
if (!osd->history.exec)
|
|
|
|
return;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:07:44 +00:00
|
|
|
int cmd = osd->history.exec - 1;
|
2018-11-18 18:06:07 +00:00
|
|
|
|
|
|
|
osd->history.exec = 0;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-11-18 18:07:44 +00:00
|
|
|
for (; cmd >= 0; cmd--)
|
|
|
|
OSD_Dispatch((const char *)osd->history.buf[cmd]);
|
|
|
|
}
|
2006-04-13 20:47:06 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_Dispatch() -- Executes a command string
|
|
|
|
//
|
2018-11-18 18:05:10 +00:00
|
|
|
static char *osd_strtoken(char *s, char **ptrptr, int *restart)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
*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
|
2018-10-07 05:23:20 +00:00
|
|
|
|
|
|
|
char *p = s ? s : *ptrptr;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
if (!p) return NULL;
|
|
|
|
|
|
|
|
// eat up any leading whitespace
|
2018-10-07 05:23:20 +00:00
|
|
|
while (*p == ' ') p++;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2018-10-07 05:23:20 +00:00
|
|
|
char *start;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
if (*p == '\"')
|
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
// quoted string
|
|
|
|
start = ++p;
|
2018-10-07 05:23:20 +00:00
|
|
|
char *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
|
2018-11-18 18:05:10 +00:00
|
|
|
void OSD_Dispatch(const char *cmd)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
char *workbuf = Xstrdup(cmd);
|
|
|
|
char *state = workbuf;
|
|
|
|
char *wtp;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
int restart = 0;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
do
|
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
char const *token;
|
|
|
|
|
2018-11-18 18:05:10 +00:00
|
|
|
if ((token = osd_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
|
2018-11-18 18:05:10 +00:00
|
|
|
if (token[0] == '/' && token[1] == '/')
|
2008-06-29 12:53:18 +00:00
|
|
|
{
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(workbuf);
|
2018-11-18 18:05:10 +00:00
|
|
|
return;
|
2017-06-27 02:24:14 +00:00
|
|
|
}
|
|
|
|
|
2018-11-18 18:05:10 +00:00
|
|
|
auto const *symbol = osd_findexactsymbol(token);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:05:10 +00:00
|
|
|
if (symbol == NULL)
|
2017-06-27 02:24:14 +00:00
|
|
|
{
|
|
|
|
static char const s_gamefunc_[] = "gamefunc_";
|
2018-11-18 18:05:10 +00:00
|
|
|
size_t constexpr strlen_gamefunc_ = ARRAY_SIZE(s_gamefunc_) - 1;
|
|
|
|
size_t const strlen_token = Bstrlen(token);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:05:10 +00:00
|
|
|
if ((strlen_gamefunc_ >= strlen_token || Bstrncmp(token, s_gamefunc_, strlen_gamefunc_)) && !m32_osd_tryscript)
|
|
|
|
OSD_Printf("%s\"%s\" is not a valid command or cvar\n", osd->draw.highlight, token);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(workbuf);
|
2018-11-18 18:05:10 +00:00
|
|
|
return;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2018-12-15 01:39:51 +00:00
|
|
|
auto name = token;
|
2018-11-18 18:05:10 +00:00
|
|
|
char const *parms[MAXPARMS] = {};
|
|
|
|
int numparms = 0;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
while (wtp && !restart)
|
|
|
|
{
|
2018-11-18 18:05:10 +00:00
|
|
|
token = osd_strtoken(NULL, &wtp, &restart);
|
|
|
|
if (token && numparms < MAXPARMS) parms[numparms++] = token;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:05:10 +00:00
|
|
|
osdfuncparm_t const ofp = { numparms, name, parms, cmd };
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:05:10 +00:00
|
|
|
if (symbol->func == OSD_ALIAS)
|
|
|
|
OSD_Dispatch(symbol->help);
|
|
|
|
else if (symbol->func != OSD_UNALIASED)
|
2017-06-27 02:24:14 +00:00
|
|
|
{
|
2018-11-18 18:05:10 +00:00
|
|
|
switch (symbol->func(&ofp))
|
2008-06-30 00:18:59 +00:00
|
|
|
{
|
2018-11-18 18:05:10 +00:00
|
|
|
default:
|
2017-06-27 02:24:14 +00:00
|
|
|
case OSDCMD_OK: break;
|
2018-11-18 18:05:10 +00:00
|
|
|
case OSDCMD_SHOWHELP: OSD_Printf("%s\n", symbol->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
|
|
|
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(workbuf);
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// OSD_RegisterFunction() -- Registers a new function
|
|
|
|
//
|
2018-11-18 18:06:15 +00:00
|
|
|
int OSD_RegisterFunction(const char *pszName, const char *pszDesc, int (*func)(osdcmdptr_t))
|
2006-04-13 20:47:06 +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
|
|
|
|
2018-11-18 18:05:32 +00:00
|
|
|
auto symb = osd_findexactsymbol(pszName);
|
2010-05-07 20:45:40 +00:00
|
|
|
|
2018-11-18 18:05:32 +00:00
|
|
|
if (!symb) // allow reusing an alias name
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:05:32 +00:00
|
|
|
symb = osd_addsymbol(pszName);
|
|
|
|
symb->name = pszName;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
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);
|
2018-10-25 23:28:56 +00:00
|
|
|
osd->version.buf = Xstrdup(pszVersion);
|
2017-06-27 02:24:14 +00:00
|
|
|
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;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
auto const newsymb = (osdsymbol_t *)Xcalloc(1, sizeof(osdsymbol_t));
|
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (!osd->symbols)
|
|
|
|
osd->symbols = newsymb;
|
2007-12-12 17:42:14 +00:00
|
|
|
else
|
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
if (!Bstrcasecmp(pszName, osd->symbols->name))
|
2007-12-12 17:42:14 +00:00
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
auto t = osd->symbols;
|
|
|
|
osd->symbols = newsymb;
|
|
|
|
osd->symbols->next = t;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-11-18 18:06:21 +00:00
|
|
|
auto s = osd->symbols;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
while (s->next)
|
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
if (Bstrcasecmp(s->next->name, pszName))
|
|
|
|
break;
|
|
|
|
|
|
|
|
s = s->next;
|
2006-04-24 19:04:22 +00:00
|
|
|
}
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
auto t = s->next;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
s->next = newsymb;
|
|
|
|
newsymb->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);
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(lowercase);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
osd->symbptrs[osd->numsymbols++] = newsymb;
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
return newsymb;
|
2006-04-13 20:47:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// findsymbol() -- Finds a symbol, possibly partially named
|
2006-04-24 19:04:22 +00:00
|
|
|
//
|
2018-10-07 05:20:47 +00:00
|
|
|
static osdsymbol_t * osd_findsymbol(const char * const pszName, osdsymbol_t *pSymbol)
|
2006-04-13 20:47:06 +00:00
|
|
|
{
|
2018-11-18 18:07:20 +00:00
|
|
|
if (osd->symbols == NULL)
|
|
|
|
return NULL;
|
2018-11-18 18:06:07 +00:00
|
|
|
|
2018-11-18 18:06:21 +00:00
|
|
|
if (!pSymbol) pSymbol = osd->symbols;
|
2006-04-13 20:47:06 +00:00
|
|
|
|
2018-10-07 05:20:47 +00:00
|
|
|
int const nameLen = Bstrlen(pszName);
|
|
|
|
|
2017-06-27 02:24:14 +00:00
|
|
|
for (; pSymbol; pSymbol=pSymbol->next)
|
2018-11-18 18:06:07 +00:00
|
|
|
{
|
2019-03-20 11:24:25 +00:00
|
|
|
if (pSymbol->func != OSD_UNALIASED && pSymbol->help != NULL && !Bstrncasecmp(pszName, pSymbol->name, nameLen))
|
2018-11-18 18:06:07 +00:00
|
|
|
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
|
|
|
{
|
2018-11-18 18:07:20 +00:00
|
|
|
if (osd->symbols == NULL)
|
|
|
|
return NULL;
|
2018-11-18 18:06:07 +00:00
|
|
|
|
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);
|
2019-06-25 11:29:08 +00:00
|
|
|
Xfree(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
|
|
|
}
|
|
|
|
|
2018-11-18 18:06:15 +00:00
|
|
|
int osdcmd_cvar_set(osdcmdptr_t parm)
|
2009-04-29 06:20:07 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
int const printValue = (parm->numparms == 0);
|
2019-03-02 23:21:16 +00:00
|
|
|
int const cvaridx = hash_findcase(&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
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
Bassert(cvaridx >= 0);
|
2017-06-27 02:24:14 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
auto pData = *osd->cvars[cvaridx].pData;
|
2009-04-30 21:09:44 +00:00
|
|
|
|
2018-11-18 18:06:07 +00:00
|
|
|
if (pData.flags & CVAR_READONLY)
|
|
|
|
{
|
|
|
|
OSD_Printf("Cvar \"%s\" is read only.\n", pData.name);
|
|
|
|
return OSDCMD_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2018-11-18 18:06:07 +00:00
|
|
|
}
|
2013-05-15 02:16:19 +00:00
|
|
|
|
|
|
|
#ifdef USE_OPENGL
|
2018-11-18 18:06:07 +00:00
|
|
|
if (!OSD_ParsingScript())
|
|
|
|
{
|
|
|
|
switch (pData.flags & (CVAR_RESTARTVID|CVAR_INVALIDATEALL|CVAR_INVALIDATEART))
|
2013-05-15 02:16:19 +00:00
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
case CVAR_RESTARTVID:
|
2019-09-21 20:53:00 +00:00
|
|
|
//osdcmd_restartvid(NULL);
|
2018-11-18 18:06:07 +00:00
|
|
|
break;
|
|
|
|
case CVAR_INVALIDATEALL:
|
|
|
|
gltexinvalidatetype(INVALIDATE_ALL);
|
|
|
|
fallthrough__;
|
|
|
|
case CVAR_INVALIDATEART:
|
|
|
|
gltexinvalidatetype(INVALIDATE_ART);
|
2013-05-15 02:16:19 +00:00
|
|
|
#ifdef POLYMER
|
2018-11-18 18:06:07 +00:00
|
|
|
if (videoGetRenderMode() == REND_POLYMER)
|
|
|
|
polymer_texinvalidate();
|
2013-05-15 02:16:19 +00:00
|
|
|
#endif
|
2018-11-18 18:06:07 +00:00
|
|
|
break;
|
2013-05-15 02:16:19 +00:00
|
|
|
}
|
2009-04-29 06:20:07 +00:00
|
|
|
}
|
2018-11-18 18:06:07 +00:00
|
|
|
#endif
|
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;
|
|
|
|
}
|
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
void OSD_WriteAliases(buildvfs_FILE fp)
|
2013-12-24 09:44:24 +00:00
|
|
|
{
|
2018-11-18 18:06:27 +00:00
|
|
|
for (auto &symb : osd->symbptrs)
|
2018-11-18 18:06:07 +00:00
|
|
|
{
|
2018-11-18 18:07:20 +00:00
|
|
|
if (symb == NULL)
|
|
|
|
break;
|
|
|
|
else if (symb->func == (void *)OSD_ALIAS)
|
2019-03-01 08:51:50 +00:00
|
|
|
{
|
|
|
|
buildvfs_fputstr(fp, "alias \"");
|
|
|
|
buildvfs_fputstrptr(fp, symb->name);
|
|
|
|
buildvfs_fputstr(fp, "\" \"");
|
|
|
|
buildvfs_fputstrptr(fp, symb->help);
|
|
|
|
buildvfs_fputstr(fp, "\"\n");
|
|
|
|
}
|
2018-11-18 18:06:07 +00:00
|
|
|
}
|
2013-12-24 09:44:24 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
void OSD_WriteCvars(buildvfs_FILE fp)
|
2009-04-29 19:43:51 +00:00
|
|
|
{
|
2018-11-18 18:06:07 +00:00
|
|
|
Bassert(fp);
|
2010-05-02 23:27:30 +00:00
|
|
|
|
2019-03-01 08:51:50 +00:00
|
|
|
char buf[64];
|
|
|
|
|
2019-05-19 03:56:13 +00:00
|
|
|
for (int 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]))
|
2018-11-18 18:06:07 +00:00
|
|
|
{
|
2017-06-27 02:24:14 +00:00
|
|
|
switch (pData.flags & CVAR_TYPEMASK)
|
2011-01-16 02:50:27 +00:00
|
|
|
{
|
2019-03-01 08:51:50 +00:00
|
|
|
case CVAR_FLOAT:
|
|
|
|
buildvfs_fputstrptr(fp, pData.name);
|
|
|
|
snprintf(buf, sizeof(buf), " \"%f\"\n", *pData.f);
|
|
|
|
buildvfs_fputstrptr(fp, buf);
|
|
|
|
break;
|
|
|
|
case CVAR_DOUBLE:
|
|
|
|
buildvfs_fputstrptr(fp, pData.name);
|
|
|
|
snprintf(buf, sizeof(buf), " \"%f\"\n", *pData.d);
|
|
|
|
buildvfs_fputstrptr(fp, buf);
|
|
|
|
break;
|
2010-05-02 23:27:30 +00:00
|
|
|
case CVAR_INT:
|
2019-03-01 08:51:50 +00:00
|
|
|
case CVAR_BOOL:
|
|
|
|
buildvfs_fputstrptr(fp, pData.name);
|
|
|
|
snprintf(buf, sizeof(buf), " \"%d\"\n", *pData.i32);
|
|
|
|
buildvfs_fputstrptr(fp, buf);
|
|
|
|
break;
|
|
|
|
case CVAR_UINT:
|
|
|
|
buildvfs_fputstrptr(fp, pData.name);
|
|
|
|
snprintf(buf, sizeof(buf), " \"%u\"\n", *pData.u32);
|
|
|
|
buildvfs_fputstrptr(fp, buf);
|
|
|
|
break;
|
|
|
|
case CVAR_STRING:
|
|
|
|
buildvfs_fputstrptr(fp, pData.name);
|
|
|
|
buildvfs_fputstr(fp, " \"");
|
|
|
|
buildvfs_fputstrptr(fp, pData.string);
|
|
|
|
buildvfs_fputstr(fp, "\"\n");
|
|
|
|
break;
|
2017-06-27 02:24:14 +00:00
|
|
|
default: EDUKE32_UNREACHABLE_SECTION(break);
|
2011-01-16 02:50:27 +00:00
|
|
|
}
|
2018-11-18 18:06:07 +00:00
|
|
|
}
|
2009-04-29 19:43:51 +00:00
|
|
|
}
|
|
|
|
}
|