Add special S9xDisplayStringType to pass additional info.

Add some arrow characters for displayed keys.
This commit is contained in:
Brandon Wright 2018-12-12 16:15:56 -06:00
parent bb66278585
commit 8a2cd602da
6 changed files with 62 additions and 31 deletions

14
font.h
View File

@ -131,13 +131,13 @@ static const char *font[] =
" ", " ",
//2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678 //2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678
" ", " ",
" ", " . . ",
" ", " .#. .#. . ..... ",
" ", " .##. .##. .#. .#####. ",
" ", " .###. .###. .###. .###. ",
" ", " .##. .##. .#####. .#. ",
" ", " .#. .#. ..... . ",
" ", " . . ",
" ", " ",
//2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678 //2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678/2345678
" ", " ",

28
gfx.cpp
View File

@ -22,7 +22,7 @@ extern struct SLineMatrixData LineMatrixData[240];
void S9xComputeClipWindows (void); void S9xComputeClipWindows (void);
static int font_width = 8, font_height = 9; static int font_width = 8, font_height = 9;
void (*S9xCustomDisplayString) (const char *, int, int, bool) = NULL; void (*S9xCustomDisplayString) (const char *, int, int, bool, int) = NULL;
static void SetupOBJ (void); static void SetupOBJ (void);
static void DrawOBJS (int); static void DrawOBJS (int);
@ -38,6 +38,7 @@ static inline void DrawBackgroundMode7 (int, void (*DrawMath) (uint32, uint32, i
static inline void DrawBackdrop (void); static inline void DrawBackdrop (void);
static inline void RenderScreen (bool8); static inline void RenderScreen (bool8);
static uint16 get_crosshair_color (uint8); static uint16 get_crosshair_color (uint8);
static void S9xDisplayStringType (const char *, int, int, bool, int);
#define TILE_PLUS(t, x) (((t) & 0xfc00) | ((t + x) & 0x3ff)) #define TILE_PLUS(t, x) (((t) & 0xfc00) | ((t + x) & 0x3ff))
@ -1827,7 +1828,7 @@ static void DisplayStringFromBottom (const char *string, int linesFromBottom, in
{ {
if (S9xCustomDisplayString) if (S9xCustomDisplayString)
{ {
S9xCustomDisplayString (string, linesFromBottom, pixelsFromLeft, allowWrap); S9xCustomDisplayString (string, linesFromBottom, pixelsFromLeft, allowWrap, S9X_NO_INFO);
return; return;
} }
@ -1862,6 +1863,17 @@ static void DisplayStringFromBottom (const char *string, int linesFromBottom, in
} }
} }
static void S9xDisplayStringType (const char *string, int linesFromBottom, int pixelsFromLeft, bool allowWrap, int type)
{
if (S9xCustomDisplayString)
{
S9xCustomDisplayString (string, linesFromBottom, pixelsFromLeft, allowWrap, type);
return;
}
S9xDisplayString (string, linesFromBottom, pixelsFromLeft, allowWrap);
}
static void DisplayFrameRate (void) static void DisplayFrameRate (void)
{ {
char string[10]; char string[10];
@ -1892,7 +1904,7 @@ static void DisplayFrameRate (void)
static void DisplayPressedKeys (void) static void DisplayPressedKeys (void)
{ {
static char KeyMap[] = { '0', '1', '2', 'R', 'L', 'X', 'A', '>', '<', 'v', '^', 'S', 's', 'Y', 'B' }; static unsigned char KeyMap[] = { '0', '1', '2', 'R', 'L', 'X', 'A', 225, 224, 227, 226, 'S', 's', 'Y', 'B' };
static int KeyOrder[] = { 8, 10, 7, 9, 0, 6, 14, 13, 5, 1, 4, 3, 2, 11, 12 }; // < ^ > v A B Y X L R S s static int KeyOrder[] = { 8, 10, 7, 9, 0, 6, 14, 13, 5, 1, 4, 3, 2, 11, 12 }; // < ^ > v A B Y X L R S s
enum controllers controller; enum controllers controller;
@ -1916,7 +1928,7 @@ static void DisplayPressedKeys (void)
uint8 buttons = buf[4]; uint8 buttons = buf[4];
sprintf(string, "#%d %d: (%03d,%03d) %c%c", port + 1, ids[0] + 1, x, y, sprintf(string, "#%d %d: (%03d,%03d) %c%c", port + 1, ids[0] + 1, x, y,
(buttons & 0x40) ? 'L' : ' ', (buttons & 0x80) ? 'R' : ' '); (buttons & 0x40) ? 'L' : ' ', (buttons & 0x80) ? 'R' : ' ');
S9xDisplayString(string, line++, 1, false); S9xDisplayStringType(string, line++, 1, false, S9X_PRESSED_KEYS_INFO);
break; break;
} }
@ -1931,7 +1943,7 @@ static void DisplayPressedKeys (void)
sprintf(string, "#%d %d: (%03d,%03d) %c%c%c%c", port + 1, ids[0] + 1, x, y, sprintf(string, "#%d %d: (%03d,%03d) %c%c%c%c", port + 1, ids[0] + 1, x, y,
(buttons & 0x80) ? 'F' : ' ', (buttons & 0x40) ? 'C' : ' ', (buttons & 0x80) ? 'F' : ' ', (buttons & 0x40) ? 'C' : ' ',
(buttons & 0x20) ? 'T' : ' ', (buttons & 0x10) ? 'P' : ' '); (buttons & 0x20) ? 'T' : ' ', (buttons & 0x10) ? 'P' : ' ');
S9xDisplayString(string, line++, 1, false); S9xDisplayStringType(string, line++, 1, false, S9X_PRESSED_KEYS_INFO);
break; break;
} }
@ -1950,7 +1962,7 @@ static void DisplayPressedKeys (void)
sprintf(string, "#%d %d: (%03d,%03d) %c%c%c / (%03d,%03d) %c%c%c", port + 1, ids[0] + 1, sprintf(string, "#%d %d: (%03d,%03d) %c%c%c / (%03d,%03d) %c%c%c", port + 1, ids[0] + 1,
x1, y1, (buttons & 0x80) ? 'T' : ' ', (buttons & 0x20) ? 'S' : ' ', offscreen1 ? 'O' : ' ', x1, y1, (buttons & 0x80) ? 'T' : ' ', (buttons & 0x20) ? 'S' : ' ', offscreen1 ? 'O' : ' ',
x2, y2, (buttons & 0x40) ? 'T' : ' ', (buttons & 0x10) ? 'S' : ' ', offscreen2 ? 'O' : ' '); x2, y2, (buttons & 0x40) ? 'T' : ' ', (buttons & 0x10) ? 'S' : ' ', offscreen2 ? 'O' : ' ');
S9xDisplayString(string, line++, 1, false); S9xDisplayStringType(string, line++, 1, false, S9X_PRESSED_KEYS_INFO);
break; break;
} }
@ -1965,7 +1977,7 @@ static void DisplayPressedKeys (void)
string[6 + i]= (pad & mask) ? KeyMap[j] : ' '; string[6 + i]= (pad & mask) ? KeyMap[j] : ' ';
} }
S9xDisplayString(string, line++, 1, false); S9xDisplayStringType(string, line++, 1, false, S9X_PRESSED_KEYS_INFO);
break; break;
} }
@ -1984,7 +1996,7 @@ static void DisplayPressedKeys (void)
string[6 + i]= (pad & mask) ? KeyMap[j] : ' '; string[6 + i]= (pad & mask) ? KeyMap[j] : ' ';
} }
S9xDisplayString(string, line++, 1, false); S9xDisplayStringType(string, line++, 1, false, S9X_PRESSED_KEYS_INFO);
} }
} }

2
gfx.h
View File

@ -191,6 +191,6 @@ void S9xSetPalette (void);
void S9xSyncSpeed (void); void S9xSyncSpeed (void);
// called instead of S9xDisplayString if set to non-NULL // called instead of S9xDisplayString if set to non-NULL
extern void (*S9xCustomDisplayString) (const char *, int, int, bool); extern void (*S9xCustomDisplayString) (const char *, int, int, bool, int type);
#endif #endif

View File

@ -1800,15 +1800,15 @@ static int StringWidth (const char *str)
return pixcount; return pixcount;
} }
static void GTKDisplayChar (int x, int y, uint8 c, bool overlap = false) static void GTKDisplayChar (int x, int y, uint8 c, bool overlap = false, bool monospace = false)
{ {
int cindex = c - 32; int cindex = c - 32;
int crow = cindex >> 4; int crow = cindex >> 4;
int ccol = cindex & 15; int ccol = cindex & 15;
int cwidth = font_width - kern[cindex][0] - kern[cindex][1]; int cwidth = font_width - (monospace ? 0 : (kern[cindex][0] + kern[cindex][1]));
int line = crow * font_height; int line = crow * font_height;
int offset = ccol * font_width + kern[cindex][0]; int offset = ccol * font_width + (monospace ? 0 : kern[cindex][0]);
int scale = IPPU.RenderedScreenWidth / SNES_WIDTH; int scale = IPPU.RenderedScreenWidth / SNES_WIDTH;
uint16 *s = GFX.Screen + y * GFX.RealPPL + x * scale; uint16 *s = GFX.Screen + y * GFX.RealPPL + x * scale;
@ -1821,7 +1821,9 @@ static void GTKDisplayChar (int x, int y, uint8 c, bool overlap = false)
if (p == '#') if (p == '#')
*s = Settings.DisplayColor; *s = Settings.DisplayColor;
else if (!overlap || w > 0) else if (monospace && p == '.')
*s = 0x0000;
else if (!monospace && (!overlap || w > 0))
*s = (*s & 0xf7de) >> 1; *s = (*s & 0xf7de) >> 1;
if (scale > 1) if (scale > 1)
@ -1834,8 +1836,11 @@ static void GTKDisplayChar (int x, int y, uint8 c, bool overlap = false)
} }
static void S9xGTKDisplayString (const char *string, int linesFromBottom, static void S9xGTKDisplayString (const char *string, int linesFromBottom,
int pixelsFromLeft, bool allowWrap) int pixelsFromLeft, bool allowWrap, int type)
{ {
bool monospace = true;
if (type == S9X_NO_INFO)
{
if (linesFromBottom <= 0) if (linesFromBottom <= 0)
linesFromBottom = 1; linesFromBottom = 1;
@ -1845,6 +1850,9 @@ static void S9xGTKDisplayString (const char *string, int linesFromBottom,
if (pixelsFromLeft > 128) if (pixelsFromLeft > 128)
pixelsFromLeft = SNES_WIDTH - StringWidth (string); pixelsFromLeft = SNES_WIDTH - StringWidth (string);
monospace = false;
}
int dst_x = pixelsFromLeft; int dst_x = pixelsFromLeft;
int dst_y = IPPU.RenderedScreenHeight - font_height * linesFromBottom; int dst_y = IPPU.RenderedScreenHeight - font_height * linesFromBottom;
int len = strlen(string); int len = strlen(string);
@ -1858,7 +1866,7 @@ static void S9xGTKDisplayString (const char *string, int linesFromBottom,
for (int i = 0 ; i < len ; i++) for (int i = 0 ; i < len ; i++)
{ {
int cindex = string[i] - 32; int cindex = string[i] - 32;
int char_width = font_width - kern[cindex][0] - kern[cindex][1]; int char_width = font_width - (monospace ? 1 : (kern[cindex][0] + kern[cindex][1]));
if (dst_x + char_width > SNES_WIDTH || (uint8) string[i] < 32) if (dst_x + char_width > SNES_WIDTH || (uint8) string[i] < 32)
{ {
@ -1876,7 +1884,8 @@ static void S9xGTKDisplayString (const char *string, int linesFromBottom,
if ((uint8) string[i] < 32) if ((uint8) string[i] < 32)
continue; continue;
GTKDisplayChar(dst_x, dst_y, string[i], overlap); GTKDisplayChar(dst_x, dst_y, string[i], overlap, monospace);
dst_x += char_width - 1; dst_x += char_width - 1;
overlap = true; overlap = true;
} }

View File

@ -370,6 +370,14 @@ gboolean S9xScreenSaverCheckFunc (gpointer data)
/* Snes9x core hooks */ /* Snes9x core hooks */
void S9xMessage (int type, int number, const char *message) void S9xMessage (int type, int number, const char *message)
{ {
switch (number)
{
case S9X_MOVIE_INFO:
S9xSetInfoString (message);
break;
default:
break;
}
} }
/* Varies from ParseArgs because this one is for the OS port to handle */ /* Varies from ParseArgs because this one is for the OS port to handle */

View File

@ -21,6 +21,7 @@ enum
// Individual message numbers // Individual message numbers
enum enum
{ {
S9X_NO_INFO,
S9X_ROM_INFO, S9X_ROM_INFO,
S9X_HEADERS_INFO, S9X_HEADERS_INFO,
S9X_CONFIG_INFO, S9X_CONFIG_INFO,
@ -51,7 +52,8 @@ enum
S9X_WRONG_MOVIE_SNAPSHOT, S9X_WRONG_MOVIE_SNAPSHOT,
S9X_NOT_A_MOVIE_SNAPSHOT, S9X_NOT_A_MOVIE_SNAPSHOT,
S9X_SNAPSHOT_INCONSISTENT, S9X_SNAPSHOT_INCONSISTENT,
S9X_AVI_INFO S9X_AVI_INFO,
S9X_PRESSED_KEYS_INFO,
}; };
#endif #endif