imgui: Update font. Test ROM status line.

This commit is contained in:
BearOso 2023-05-03 16:44:36 -05:00
parent c9f1e8d79b
commit b11ecf932a
6 changed files with 4056 additions and 4435 deletions

View File

@ -1,9 +1,10 @@
#include "snes9x_imgui.h" #include "snes9x_imgui.h"
#include "snes9x_imgui_vera.h" #include "snes9x_imgui_noto.h"
#include "imgui.h" #include "imgui.h"
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <array>
#include "snes9x.h" #include "snes9x.h"
#include "port.h" #include "port.h"
@ -20,12 +21,14 @@ namespace
static void ImGui_DrawPressedKeys(int spacing) static void ImGui_DrawPressedKeys(int spacing)
{ {
const char *keynames[] = { " ", " ", " ", "R", "L", "X", "A", "", "", "", "", "S", "s", "Y", "B" }; const std::array<const char *, 15> keynames =
const 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 { " ", " ", " ", "R", "L", "X", "A", "", "", "", "", "St", "Sel", "Y", "B" };
const std::array<int, 12> keyorder =
{ 10, 9, 8, 7, 6, 14, 13, 5, 4, 3, 11, 12 }; // < ^ > v A B Y X L R S s
enum controllers controller; enum controllers controller;
int num_lines = 0; int num_lines = 0;
int cell_width = ImGui::CalcTextSize("--").x; int cell_width = ImGui::CalcTextSize("").x;
int8_t ids[4]; int8_t ids[4];
std::string final_string; std::string final_string;
@ -77,7 +80,7 @@ static void ImGui_DrawPressedKeys(int spacing)
case CTL_JOYPAD: { case CTL_JOYPAD: {
std::string prefix = "#" + std::to_string(port + 1) + " "; std::string prefix = "#" + std::to_string(port + 1) + " ";
auto prefix_size = ImGui::CalcTextSize(prefix.c_str()); auto prefix_size = ImGui::CalcTextSize(prefix.c_str());
int box_width = 2 * spacing + prefix_size.x + cell_width * 15; int box_width = 2 * spacing + prefix_size.x + cell_width * keyorder.size();
int box_height = 2 * spacing + prefix_size.y; int box_height = 2 * spacing + prefix_size.y;
int x = (ImGui::GetIO().DisplaySize.x - box_width) / 2; int x = (ImGui::GetIO().DisplaySize.x - box_width) / 2;
int y = ImGui::GetIO().DisplaySize.y - (spacing + box_height) * num_lines; int y = ImGui::GetIO().DisplaySize.y - (spacing + box_height) * num_lines;
@ -93,7 +96,7 @@ static void ImGui_DrawPressedKeys(int spacing)
x += prefix_size.x; x += prefix_size.x;
uint16 pad = MovieGetJoypad(ids[0]); uint16 pad = MovieGetJoypad(ids[0]);
for (int i = 0; i < 15; i++) for (size_t i = 0; i < keyorder.size(); i++)
{ {
int j = keyorder[i]; int j = keyorder[i];
int mask = (1 << (j + 1)); int mask = (1 << (j + 1));
@ -272,8 +275,9 @@ void S9xImGuiInit(S9xImGuiInitInfo *init_info)
ImFontGlyphRangesBuilder builder; ImFontGlyphRangesBuilder builder;
builder.Clear(); builder.Clear();
builder.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesDefault()); builder.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesDefault());
builder.AddText("↑←↓→▶❚"); builder.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesJapanese());
builder.AddText("←↑→↓▶❚");
ranges.clear(); ranges.clear();
builder.BuildRanges(&ranges); builder.BuildRanges(&ranges);
ImGui::GetIO().Fonts->AddFontFromMemoryCompressedBase85TTF(imgui_roboto_font_compressed_data_base85, settings.font_size, nullptr, ranges.Data); ImGui::GetIO().Fonts->AddFontFromMemoryCompressedBase85TTF(imgui_noto_font_compressed_data_base85, settings.font_size, nullptr, ranges.Data);
} }

3992
external/imgui/snes9x_imgui_noto.h vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -25,6 +25,9 @@
#include "gfx.h" #include "gfx.h"
#include "memmap.h" #include "memmap.h"
#include "ppu.h" #include "ppu.h"
#include "fmt/format.h"
#include <iomanip>
static void S9xThrottle(int); static void S9xThrottle(int);
static void S9xCheckPointerTimer(); static void S9xCheckPointerTimer();
@ -351,7 +354,6 @@ static bool S9xScreenSaverCheckFunc()
return true; return true;
} }
/* Snes9x core hooks */ /* Snes9x core hooks */
void S9xMessage(int type, int number, const char *message) void S9xMessage(int type, int number, const char *message)
{ {
@ -360,6 +362,11 @@ void S9xMessage(int type, int number, const char *message)
case S9X_MOVIE_INFO: case S9X_MOVIE_INFO:
S9xSetInfoString(message); S9xSetInfoString(message);
break; break;
case S9X_ROM_INFO:
{
S9xSetInfoString(Memory.GetMultilineROMInfo().c_str());
break;
}
default: default:
break; break;
} }

View File

@ -5,6 +5,8 @@
\*****************************************************************************/ \*****************************************************************************/
#include <string> #include <string>
#include <iomanip>
#include <sstream>
#include <numeric> #include <numeric>
#include <assert.h> #include <assert.h>
@ -3266,7 +3268,7 @@ const char * CMemory::StaticRAMSize (void)
if (SRAMSize > 16) if (SRAMSize > 16)
strcpy(str, "Corrupt"); strcpy(str, "Corrupt");
else else
sprintf(str, "%dKbits", 8 * (SRAMMask + 1) / 1024); sprintf(str, "%d Kbit", 8 * (SRAMMask + 1) / 1024);
return (str); return (str);
} }
@ -3280,7 +3282,7 @@ const char * CMemory::Size (void)
else if (ROMSize < 7 || ROMSize - 7 > 23) else if (ROMSize < 7 || ROMSize - 7 > 23)
strcpy(str, "Corrupt"); strcpy(str, "Corrupt");
else else
sprintf(str, "%dMbits", 1 << (ROMSize - 7)); sprintf(str, "%d Mbit", 1 << (ROMSize - 7));
return (str); return (str);
} }
@ -3374,6 +3376,45 @@ const char * CMemory::PublishingCompany (void)
return (nintendo_licensees[CompanyId]); return (nintendo_licensees[CompanyId]);
} }
static std::string sjis_to_utf8(std::string in)
{
std::string out;
for (const auto &i : in)
{
unsigned char c = i;
if (c > 160 && c < 192)
out += "\357\275";
else if (c >= 192)
{
out += "\357\276";
c -= 0x40;
}
out += c;
}
return out;
}
std::string CMemory::GetMultilineROMInfo()
{
bool8 isChecksumOK = (Memory.ROMChecksum + Memory.ROMComplementChecksum == 0xffff) &&
(Memory.ROMChecksum == Memory.CalculatedChecksum);
std::string utf8_romname = sjis_to_utf8(Memory.ROMName);
std::string tvstandard = Settings.PAL ? "PAL" : "NTSC";
std::string checksum = isChecksumOK ? "Checksum OK"
: Settings.IsPatched == 3 ? "UPS patched"
: Settings.IsPatched == 2 ? "BPS patched"
: Settings.IsPatched == 1 ? "IPS patched"
: "Invalid Checksum";
std::stringstream ss;
ss << "\"" << utf8_romname << "\" (" + tvstandard + ") version " << Memory.Revision() << "\n";
ss << Memory.KartContents() << ": " << Memory.MapType() << ": " << Memory.Size() << ", SRAM: " << Memory.StaticRAMSize() << "\n";
ss << "ID: " << Memory.ROMId << ", CRC32: " << std::setfill('0') << std::setw(8) << std::setbase(16) << Memory.ROMCRC32 << ", " << checksum;
return ss.str();
}
void CMemory::MakeRomInfoText (char *romtext) void CMemory::MakeRomInfoText (char *romtext)
{ {
char temp[256]; char temp[256];

View File

@ -176,6 +176,7 @@ struct CMemory
void CheckForAnyPatch (const char *, bool8, int32 &); void CheckForAnyPatch (const char *, bool8, int32 &);
void MakeRomInfoText (char *); void MakeRomInfoText (char *);
std::string GetMultilineROMInfo();
const char * MapType (void); const char * MapType (void);
const char * StaticRAMSize (void); const char * StaticRAMSize (void);