Skip to content

Commit

Permalink
Add special S9xDisplayStringType to pass additional info.
Browse files Browse the repository at this point in the history
Add some arrow characters for displayed keys.
  • Loading branch information
bearoso committed Dec 12, 2018
1 parent bb66278 commit 8a2cd60
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 31 deletions.
14 changes: 7 additions & 7 deletions font.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
" ",
Expand Down
30 changes: 21 additions & 9 deletions gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extern struct SLineMatrixData LineMatrixData[240];
void S9xComputeClipWindows (void);

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 DrawOBJS (int);
Expand All @@ -38,6 +38,7 @@ static inline void DrawBackgroundMode7 (int, void (*DrawMath) (uint32, uint32, i
static inline void DrawBackdrop (void);
static inline void RenderScreen (bool8);
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))

Expand Down Expand Up @@ -1827,7 +1828,7 @@ static void DisplayStringFromBottom (const char *string, int linesFromBottom, in
{
if (S9xCustomDisplayString)
{
S9xCustomDisplayString (string, linesFromBottom, pixelsFromLeft, allowWrap);
S9xCustomDisplayString (string, linesFromBottom, pixelsFromLeft, allowWrap, S9X_NO_INFO);
return;
}

Expand Down Expand Up @@ -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)
{
char string[10];
Expand Down Expand Up @@ -1892,8 +1904,8 @@ static void DisplayFrameRate (void)

static void DisplayPressedKeys (void)
{
static char KeyMap[] = { '0', '1', '2', 'R', 'L', 'X', 'A', '>', '<', 'v', '^', '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 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

enum controllers controller;
int line = Settings.DisplayMovieFrame && S9xMovieActive() ? 2 : 1;
Expand All @@ -1916,7 +1928,7 @@ static void DisplayPressedKeys (void)
uint8 buttons = buf[4];
sprintf(string, "#%d %d: (%03d,%03d) %c%c", port + 1, ids[0] + 1, x, y,
(buttons & 0x40) ? 'L' : ' ', (buttons & 0x80) ? 'R' : ' ');
S9xDisplayString(string, line++, 1, false);
S9xDisplayStringType(string, line++, 1, false, S9X_PRESSED_KEYS_INFO);
break;
}

Expand All @@ -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,
(buttons & 0x80) ? 'F' : ' ', (buttons & 0x40) ? 'C' : ' ',
(buttons & 0x20) ? 'T' : ' ', (buttons & 0x10) ? 'P' : ' ');
S9xDisplayString(string, line++, 1, false);
S9xDisplayStringType(string, line++, 1, false, S9X_PRESSED_KEYS_INFO);
break;
}

Expand All @@ -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,
x1, y1, (buttons & 0x80) ? 'T' : ' ', (buttons & 0x20) ? 'S' : ' ', offscreen1 ? '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;
}

Expand All @@ -1965,7 +1977,7 @@ static void DisplayPressedKeys (void)
string[6 + i]= (pad & mask) ? KeyMap[j] : ' ';
}

S9xDisplayString(string, line++, 1, false);
S9xDisplayStringType(string, line++, 1, false, S9X_PRESSED_KEYS_INFO);
break;
}

Expand All @@ -1984,7 +1996,7 @@ static void DisplayPressedKeys (void)
string[6 + i]= (pad & mask) ? KeyMap[j] : ' ';
}

S9xDisplayString(string, line++, 1, false);
S9xDisplayStringType(string, line++, 1, false, S9X_PRESSED_KEYS_INFO);
}
}

Expand Down
2 changes: 1 addition & 1 deletion gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,6 @@ void S9xSetPalette (void);
void S9xSyncSpeed (void);

// 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
35 changes: 22 additions & 13 deletions gtk/src/gtk_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1800,15 +1800,15 @@ static int StringWidth (const char *str)
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 crow = cindex >> 4;
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 offset = ccol * font_width + kern[cindex][0];
int offset = ccol * font_width + (monospace ? 0 : kern[cindex][0]);
int scale = IPPU.RenderedScreenWidth / SNES_WIDTH;

uint16 *s = GFX.Screen + y * GFX.RealPPL + x * scale;
Expand All @@ -1821,7 +1821,9 @@ static void GTKDisplayChar (int x, int y, uint8 c, bool overlap = false)

if (p == '#')
*s = Settings.DisplayColor;
else if (!overlap || w > 0)
else if (monospace && p == '.')
*s = 0x0000;
else if (!monospace && (!overlap || w > 0))
*s = (*s & 0xf7de) >> 1;

if (scale > 1)
Expand All @@ -1834,16 +1836,22 @@ static void GTKDisplayChar (int x, int y, uint8 c, bool overlap = false)
}

static void S9xGTKDisplayString (const char *string, int linesFromBottom,
int pixelsFromLeft, bool allowWrap)
int pixelsFromLeft, bool allowWrap, int type)
{
if (linesFromBottom <= 0)
linesFromBottom = 1;
bool monospace = true;
if (type == S9X_NO_INFO)
{
if (linesFromBottom <= 0)
linesFromBottom = 1;

if (linesFromBottom >= 5)
linesFromBottom -= 3;

if (linesFromBottom >= 5)
linesFromBottom -= 3;
if (pixelsFromLeft > 128)
pixelsFromLeft = SNES_WIDTH - StringWidth (string);

if (pixelsFromLeft > 128)
pixelsFromLeft = SNES_WIDTH - StringWidth (string);
monospace = false;
}

int dst_x = pixelsFromLeft;
int dst_y = IPPU.RenderedScreenHeight - font_height * linesFromBottom;
Expand All @@ -1858,7 +1866,7 @@ static void S9xGTKDisplayString (const char *string, int linesFromBottom,
for (int i = 0 ; i < len ; i++)
{
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)
{
Expand All @@ -1876,7 +1884,8 @@ static void S9xGTKDisplayString (const char *string, int linesFromBottom,
if ((uint8) string[i] < 32)
continue;

GTKDisplayChar(dst_x, dst_y, string[i], overlap);
GTKDisplayChar(dst_x, dst_y, string[i], overlap, monospace);

dst_x += char_width - 1;
overlap = true;
}
Expand Down
8 changes: 8 additions & 0 deletions gtk/src/gtk_s9x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ gboolean S9xScreenSaverCheckFunc (gpointer data)
/* Snes9x core hooks */
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 */
Expand Down
4 changes: 3 additions & 1 deletion messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum
// Individual message numbers
enum
{
S9X_NO_INFO,
S9X_ROM_INFO,
S9X_HEADERS_INFO,
S9X_CONFIG_INFO,
Expand Down Expand Up @@ -51,7 +52,8 @@ enum
S9X_WRONG_MOVIE_SNAPSHOT,
S9X_NOT_A_MOVIE_SNAPSHOT,
S9X_SNAPSHOT_INCONSISTENT,
S9X_AVI_INFO
S9X_AVI_INFO,
S9X_PRESSED_KEYS_INFO,
};

#endif

0 comments on commit 8a2cd60

Please sign in to comment.