Skip to content

Commit

Permalink
Screen view modes: RGB/GRB/Grayscale
Browse files Browse the repository at this point in the history
  • Loading branch information
nzeemin committed Jul 18, 2024
1 parent 2f5f528 commit 0666b42
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 4 deletions.
43 changes: 41 additions & 2 deletions emulator/Emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const BYTE m_arrDigitKeyScans[] =
0176, 0030, 0031, 0032, 0013, 0034, 0035, 0016, 0017, 0177 // 0, 1, ... 9
};

const uint32_t ScreenView_StandardGRBColors[16 * 8] =
// Table for color conversion yrgb (4 bits) -> DWORD (32 bits)
const uint32_t ScreenView_StandardRGBColors[16 * 8] =
{
0xFF000000, 0xFF800000, 0xFF008000, 0xFF808000, 0xFF000080, 0xFF800080, 0xFF008080, 0xFF808080,
0xFF000000, 0xFFFF0000, 0xFF00FF00, 0xFFFFFF00, 0xFF0000FF, 0xFFFF00FF, 0xFF00FFFF, 0xFFFFFFFF,
Expand All @@ -88,7 +89,45 @@ const uint32_t ScreenView_StandardGRBColors[16 * 8] =
0xFF000000, 0xFF600000, 0xFF006000, 0xFF606000, 0xFF000060, 0xFF600060, 0xFF006060, 0xFF606060,
0xFF000000, 0xFFDF0000, 0xFF00DF00, 0xFFDFDF00, 0xFF0000DF, 0xFFDF00DF, 0xFF00DFDF, 0xFFDFDFDF,
};

const uint32_t ScreenView_StandardGRBColors[16 * 8] =
{
0xFF000000, 0xFF800000, 0xFF000080, 0xFF800080, 0xFF008000, 0xFF808000, 0xFF008080, 0xFF808080,
0xFF000000, 0xFFFF0000, 0xFF0000FF, 0xFFFF00FF, 0xFF00FF00, 0xFFFFFF00, 0xFF00FFFF, 0xFFFFFFFF,
0xFF000000, 0xFF600000, 0xFF000080, 0xFF600080, 0xFF008000, 0xFF608000, 0xFF008080, 0xFF608080,
0xFF000000, 0xFFDF0000, 0xFF0000FF, 0xFFDF00FF, 0xFF00FF00, 0xFFDFFF00, 0xFF00FFFF, 0xFFDFFFFF,
0xFF000000, 0xFF800000, 0xFF000060, 0xFF800060, 0xFF008000, 0xFF808000, 0xFF008060, 0xFF808060,
0xFF000000, 0xFFFF0000, 0xFF0000DF, 0xFFFF00DF, 0xFF00FF00, 0xFFFFFF00, 0xFF00FFDF, 0xFFFFFFDF,
0xFF000000, 0xFF600000, 0xFF000060, 0xFF600060, 0xFF008000, 0xFF608000, 0xFF008060, 0xFF608060,
0xFF000000, 0xFFDF0000, 0xFF0000DF, 0xFFDF00DF, 0xFF00FF00, 0xFFDFFF00, 0xFF00FFDF, 0xFFDFFFDF,
0xFF000000, 0xFF800000, 0xFF000080, 0xFF800080, 0xFF006000, 0xFF806000, 0xFF006080, 0xFF806080,
0xFF000000, 0xFFFF0000, 0xFF0000FF, 0xFFFF00FF, 0xFF00DF00, 0xFFFFDF00, 0xFF00DFFF, 0xFFFFDFFF,
0xFF000000, 0xFF600000, 0xFF000080, 0xFF600080, 0xFF006000, 0xFF606000, 0xFF006080, 0xFF606080,
0xFF000000, 0xFFDF0000, 0xFF0000FF, 0xFFDF00FF, 0xFF00DF00, 0xFFDFDF00, 0xFF00DFFF, 0xFFDFDFFF,
0xFF000000, 0xFF800000, 0xFF000060, 0xFF800060, 0xFF006000, 0xFF806000, 0xFF006060, 0xFF806060,
0xFF000000, 0xFFFF0000, 0xFF0000DF, 0xFFFF00DF, 0xFF00DF00, 0xFFFFDF00, 0xFF00DFDF, 0xFFFFDFDF,
0xFF000000, 0xFF600000, 0xFF000060, 0xFF600060, 0xFF006000, 0xFF606000, 0xFF006060, 0xFF606060,
0xFF000000, 0xFFDF0000, 0xFF0000DF, 0xFFDF00DF, 0xFF00DF00, 0xFFDFDF00, 0xFF00DFDF, 0xFFDFDFDF,
};
// Table for color conversion, gray (black and white) display
const uint32_t ScreenView_StandardGrayColors[16 * 8] =
{
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
0xFF000000, 0xFF242424, 0xFF484848, 0xFF6C6C6C, 0xFF909090, 0xFFB4B4B4, 0xFFD8D8D8, 0xFFFFFFFF,
};

//////////////////////////////////////////////////////////////////////

Expand Down
3 changes: 3 additions & 0 deletions emulator/Emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ extern uint16_t g_wEmulatorPrevCpuPC; // Previous PC value
extern uint16_t g_wEmulatorPpuPC; // Current PC value
extern uint16_t g_wEmulatorPrevPpuPC; // Previous PC value

extern const uint32_t ScreenView_StandardRGBColors[16 * 8];
extern const uint32_t ScreenView_StandardGRBColors[16 * 8];
extern const uint32_t ScreenView_StandardGrayColors[16 * 8];


//////////////////////////////////////////////////////////////////////

Expand Down
10 changes: 10 additions & 0 deletions emulator/Main.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ void Settings_SetCartridgeFilePath(int slot, LPCTSTR sFilePath);
void Settings_GetCartridgeFilePath(int slot, LPTSTR buffer);
void Settings_SetHardFilePath(int slot, LPCTSTR sFilePath);
void Settings_GetHardFilePath(int slot, LPTSTR buffer);
void Settings_SetScreenViewMode(int mode);
int Settings_GetScreenViewMode();
void Settings_SetScreenshotMode(int mode);
int Settings_GetScreenshotMode();
BOOL Settings_GetDebugCpuPpu();
Expand Down Expand Up @@ -159,6 +161,14 @@ void ImGuiMainMenu();
void ControlView_ImGuiWidget();

// ScreenView

enum ScreenViewMode
{
RGBScreen = 0,
GRBScreen = 1,
GrayScreen = 2,
};

void ScreenView_Init();
void ScreenView_Done();
void ScreenView_ImGuiWidget();
Expand Down
38 changes: 38 additions & 0 deletions emulator/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ void ImGuiSettingsPopup();
void ImGuiAboutPopup();

void MainWindow_DoEmulatorSpeed(WORD speed);
void MainWindow_DoScreenViewMode(ScreenViewMode mode);
void MainWindow_DoFloppyImageSelect(int slot);
void MainWindow_DoFloppyImageEject(int slot);
void MainWindow_DoCartridgeSelect(int slot);
Expand Down Expand Up @@ -102,6 +103,20 @@ void ImGuiMainMenu()
}
if (ImGui::BeginMenu("View"))
{
int viewmode = Settings_GetScreenViewMode();
bool checkedRGB = viewmode == 0;
ImGui::BeginDisabled(checkedRGB);
if (ImGui::MenuItem("RGB Screen", nullptr, &checkedRGB)) MainWindow_DoScreenViewMode(RGBScreen);
ImGui::EndDisabled();
bool checkedGRB = viewmode == 1;
ImGui::BeginDisabled(checkedGRB);
if (ImGui::MenuItem("GRB Screen", nullptr, &checkedGRB)) MainWindow_DoScreenViewMode(GRBScreen);
ImGui::EndDisabled();
bool checkedGray = viewmode == 2;
ImGui::BeginDisabled(checkedGray);
if (ImGui::MenuItem("Grayscale Screen", nullptr, &checkedGray)) MainWindow_DoScreenViewMode(GrayScreen);
ImGui::EndDisabled();

ImGui::EndMenu();
}
if (ImGui::BeginMenu("Emulator"))
Expand Down Expand Up @@ -292,6 +307,24 @@ void ControlView_ImGuiWidget()
if (ImGui::Button("Max")) MainWindow_DoEmulatorSpeed(0);
ImGui::EndDisabled();

ImGui::SeparatorText("Video");
int viewmode = Settings_GetScreenViewMode();
ImGui::BeginDisabled(viewmode == 0);
if (ImGui::Button("RGB")) MainWindow_DoScreenViewMode(RGBScreen);
ImGui::EndDisabled();
ImGui::SameLine(0.0f, 0.0f);
ImGui::BeginDisabled(viewmode == 1);
if (ImGui::Button("GRB")) MainWindow_DoScreenViewMode(GRBScreen);
ImGui::EndDisabled();
ImGui::SameLine(0.0f, 0.0f);
ImGui::BeginDisabled(viewmode == 2);
if (ImGui::Button("Gray")) MainWindow_DoScreenViewMode(GrayScreen);
ImGui::EndDisabled();

//ImGui::TextDisabled("X: ");
//ImGui::SameLine();
//ImGui::TextDisabled("Y: ");

ImGui::SeparatorText("Floppies");
for (int floppyslot = 0; floppyslot < 4; floppyslot++)
{
Expand Down Expand Up @@ -399,6 +432,11 @@ void MainWindow_DoEmulatorSpeed(WORD speed)
Emulator_SetSpeed(speed);
}

void MainWindow_DoScreenViewMode(ScreenViewMode mode)
{
Settings_SetScreenViewMode(mode);
}

void MainWindow_DoFloppyImageSelect(int slot)
{
// File Open dialog
Expand Down
2 changes: 1 addition & 1 deletion emulator/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ void Settings_SetCartridgeFilePath(int slot, LPCTSTR sFilePath)
Settings_SaveStringValue(bufValueName, sFilePath);
}

SETTINGS_GETSET_DWORD(ScreenViewMode, _T("ScreenViewMode"), int, 0);
SETTINGS_GETSET_DWORD(ScreenViewMode, _T("ScreenViewMode"), int, 1);

SETTINGS_GETSET_DWORD(ScreenHeightMode, _T("ScreenHeightMode"), int, 0);

Expand Down
11 changes: 10 additions & 1 deletion emulator/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,16 @@ int main(int, char**)

//TODO: Move to ScreenView
IM_ASSERT(m_bits != nullptr);
Emulator_PrepareScreenRGB32(m_bits, ScreenView_StandardGRBColors);
int viewmode = Settings_GetScreenViewMode();
const uint32_t* palette;
if (viewmode == RGBScreen)
palette = ScreenView_StandardRGBColors;
else if (viewmode == GrayScreen)
palette = ScreenView_StandardGrayColors;
else
palette = ScreenView_StandardGRBColors;

Emulator_PrepareScreenRGB32(m_bits, palette);

glBindTexture(GL_TEXTURE_2D, screen_texture);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, UKNC_SCREEN_WIDTH, UKNC_SCREEN_HEIGHT, GL_RGBA, GL_UNSIGNED_BYTE, m_bits);
Expand Down

0 comments on commit 0666b42

Please sign in to comment.