PSP engines lack of a command history is a major nuisance when it comes to debugging and testing ... even with the on-screen keyboard it takes WAY too long to get things done.
Anyway, this modification is borrowed almost verbatim from ezQuake 1.9.
I feel it is superior to the incarnation in JoeQuake because the command line history is human readable and editable, whereas the JoeQuake (SonsQuake, actually ... for those who remember that engine) method ends up with a lot of 0x00 characters in it.
Anyways ...
1. Host.c
Find and add the yellow ...
2a. Keys.cscr_disabled_for_loading = true;
Host_WriteConfiguration ();
if (con_initialized)
History_Shutdown ();
CDAudio_Shutdown ();
Add this above the Key_Init function ...
Code: Select all
// Added by VVD {
void History_Init (void)
{
int i, c;
FILE *hf;
for (i = 0; i < CMDLINES; i++) {
key_lines[i][0] = ']';
key_lines[i][1] = 0;
}
key_linepos = 1;
// if (cl_savehistory.value)
if ((hf = fopen(HISTORY_FILE_NAME, "rt")))
{
do
{
i = 1;
do
{
c = fgetc(hf);
key_lines[edit_line][i++] = c;
} while (c != '\n' && c != EOF && i < MAXCMDLINE);
key_lines[edit_line][i - 1] = 0;
edit_line = (edit_line + 1) & (CMDLINES - 1);
} while (c != EOF && edit_line < CMDLINES);
fclose(hf);
history_line = edit_line = (edit_line - 1) & (CMDLINES - 1);
key_lines[edit_line][0] = ']';
key_lines[edit_line][1] = 0;
}
}
void History_Shutdown (void)
{
int i;
FILE *hf;
// if (cl_savehistory.value)
if ((hf = fopen(HISTORY_FILE_NAME, "wt")))
{
i = edit_line;
do
{
i = (i + 1) & (CMDLINES - 1);
} while (i != edit_line && !key_lines[i][1]);
do
{
// fprintf(hf, "%s\n", wcs2str(key_lines[i] + 1)); // Baker: I commented this line out because byte colored text isn't a feature in most ordinary engines
fprintf(hf, "%s\n", key_lines[i] + 1);
i = (i + 1) & (CMDLINES - 1);
} while (i != edit_line && key_lines[i][1]);
fclose(hf);
}
}
// } Added by VVD
Find ...
Code: Select all
#define MAXCMDLINE 256
char key_lines[32][MAXCMDLINE];
Code: Select all
#define HISTORY_FILE_NAME "id1/quake_history.txt"
#define MAXCMDLINE 256
#define CMDLINES 32
char key_lines[CMDLINES][MAXCMDLINE];
2c. Still in keys.c ... finally ....
void Key_Init (void)
{
int i;
History_Init ();
#if 0 // This section of code is now done in History_Init
for (i=0 ; i<32 ; i++)
{
key_lines[0] = ']';
key_lines[1] = 0;
}
key_linepos = 1;
#endif