Skip to content

Commit

Permalink
Add horizontal overscan options for 284 and 320 pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 13, 2024
1 parent 13c4cb7 commit c917c95
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 68 deletions.
11 changes: 7 additions & 4 deletions platforms/desktop-shared/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ static void update_debug_sprite_buffers(void);

void emu_init(void)
{
int screen_size = GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN;
int screen_size = GC_RESOLUTION_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_HEIGHT_WITH_OVERSCAN;

emu_frame_buffer = new u8[screen_size * 3];

Expand Down Expand Up @@ -335,7 +335,10 @@ void emu_set_overscan(int overscan)
gearcoleco->GetVideo()->SetOverscan(Video::OverscanTopBottom);
break;
case 2:
gearcoleco->GetVideo()->SetOverscan(Video::OverscanFull);
gearcoleco->GetVideo()->SetOverscan(Video::OverscanFull284);
break;
case 3:
gearcoleco->GetVideo()->SetOverscan(Video::OverscanFull320);
break;
default:
gearcoleco->GetVideo()->SetOverscan(Video::OverscanDisabled);
Expand Down Expand Up @@ -480,7 +483,7 @@ static void update_debug_background_buffer(void)

for (int line = 0; line < 192; line++)
{
int line_offset = line * GC_RESOLUTION_MAX_WIDTH;
int line_offset = line * GC_RESOLUTION_WIDTH;
int tile_y = line >> 3;
int tile_y_offset = line & 7;

Expand Down Expand Up @@ -517,7 +520,7 @@ static void update_debug_background_buffer(void)

for (int line = 0; line < 192; line++)
{
int line_offset = line * GC_RESOLUTION_MAX_WIDTH;
int line_offset = line * GC_RESOLUTION_WIDTH;
int tile_y = line >> 3;
int tile_y_offset = line & 7;
region = (tile_y & 0x18) << 5;
Expand Down
18 changes: 9 additions & 9 deletions platforms/desktop-shared/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void gui_init(void)
if (strlen(bios_path) > 0)
emu_load_bios(bios_path);

emu_set_overscan(config_debug.debug ? false : config_video.overscan);
emu_set_overscan(config_debug.debug ? 0 : config_video.overscan);
}

void gui_destroy(void)
Expand Down Expand Up @@ -213,7 +213,7 @@ void gui_load_rom(const char* path)
{
emu_pause();

for (int i=0; i < (GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN); i++)
for (int i=0; i < (GC_RESOLUTION_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_HEIGHT_WITH_OVERSCAN); i++)
{
emu_frame_buffer[i] = 0;
}
Expand Down Expand Up @@ -465,10 +465,10 @@ static void main_menu(void)

if (ImGui::BeginMenu("Overscan"))
{
ImGui::PushItemWidth(120.0f);
if (ImGui::Combo("##overscan", &config_video.overscan, "Disabled\0Top+Bottom\0Full\0\0"))
ImGui::PushItemWidth(150.0f);
if (ImGui::Combo("##overscan", &config_video.overscan, "Disabled\0Top+Bottom\0Full (284 width)\0Full (320 width)\0\0"))
{
emu_set_overscan(config_debug.debug ? false : config_video.overscan);
emu_set_overscan(config_debug.debug ? 0 : config_video.overscan);
}
ImGui::PopItemWidth();
ImGui::EndMenu();
Expand Down Expand Up @@ -740,7 +740,7 @@ static void main_menu(void)

if (ImGui::MenuItem("Enable", "", &config_debug.debug))
{
emu_set_overscan(config_debug.debug ? false : config_video.overscan);
emu_set_overscan(config_debug.debug ? 0 : config_video.overscan);

if (config_debug.debug)
emu_debug_step();
Expand Down Expand Up @@ -1011,8 +1011,8 @@ static void main_window(void)
gui_main_window_hovered = ImGui::IsWindowHovered();
}

float tex_h = (float)runtime.screen_width / (float)(GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN);
float tex_v = (float)runtime.screen_height / (float)(GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN);
float tex_h = (float)runtime.screen_width / (float)(GC_RESOLUTION_WIDTH_WITH_OVERSCAN);
float tex_v = (float)runtime.screen_height / (float)(GC_RESOLUTION_HEIGHT_WITH_OVERSCAN);

ImGui::Image((void*)(intptr_t)renderer_emu_texture, ImVec2((float)main_window_width, (float)main_window_height), ImVec2(0, 0), ImVec2(tex_h, tex_v));

Expand Down Expand Up @@ -1425,7 +1425,7 @@ static void menu_reset(void)
{
emu_pause();

for (int i=0; i < (GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN); i++)
for (int i=0; i < (GC_RESOLUTION_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_HEIGHT_WITH_OVERSCAN); i++)
{
emu_frame_buffer[i] = 0;
}
Expand Down
4 changes: 2 additions & 2 deletions platforms/desktop-shared/gui_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,8 +1117,8 @@ static void debug_window_vram_sprites(void)
ImVec2 p_screen = ImGui::GetCursorScreenPos();

float screen_scale = 1.0f;
float tex_h = (float)runtime.screen_width / (float)(GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN);
float tex_v = (float)runtime.screen_height / (float)(GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN);
float tex_h = (float)runtime.screen_width / (float)(GC_RESOLUTION_WIDTH_WITH_OVERSCAN);
float tex_v = (float)runtime.screen_height / (float)(GC_RESOLUTION_HEIGHT_WITH_OVERSCAN);

ImGui::Image((void*)(intptr_t)renderer_emu_texture, ImVec2(runtime.screen_width * screen_scale, runtime.screen_height * screen_scale), ImVec2(0, 0), ImVec2(tex_h, tex_v));

Expand Down
6 changes: 3 additions & 3 deletions platforms/desktop-shared/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ static u32 scanlines[16] = {
0x000000FF, 0x000000FF, 0x000000FF, 0x000000FF,
0x000000FF, 0x000000FF, 0x000000FF, 0x000000FF};
static const int FRAME_BUFFER_SCALE = 4;
static const int FRAME_BUFFER_WIDTH = GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN * FRAME_BUFFER_SCALE;
static const int FRAME_BUFFER_HEIGHT = GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN * FRAME_BUFFER_SCALE;
static const int FRAME_BUFFER_WIDTH = GC_RESOLUTION_WIDTH_WITH_OVERSCAN * FRAME_BUFFER_SCALE;
static const int FRAME_BUFFER_HEIGHT = GC_RESOLUTION_HEIGHT_WITH_OVERSCAN * FRAME_BUFFER_SCALE;

static void init_ogl_gui(void);
static void init_ogl_emu(void);
Expand Down Expand Up @@ -158,7 +158,7 @@ static void init_ogl_emu(void)
glBindFramebuffer(GL_FRAMEBUFFER, 0);

glBindTexture(GL_TEXTURE_2D, system_texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN, GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*) emu_frame_buffer);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, GC_RESOLUTION_WIDTH_WITH_OVERSCAN, GC_RESOLUTION_HEIGHT_WITH_OVERSCAN, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*) emu_frame_buffer);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

Expand Down
14 changes: 8 additions & 6 deletions platforms/libretro/libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void fallback_log(enum retro_log_level level, const char *fmt, ...)
static const struct retro_variable vars[] = {
{ "gearcoleco_timing", "Refresh Rate (restart); Auto|NTSC (60 Hz)|PAL (50 Hz)" },
{ "gearcoleco_aspect_ratio", "Aspect Ratio (restart); 1:1 PAR|4:3 PAR|16:9 PAR" },
{ "gearcoleco_overscan", "Overscan; Disabled|Top+Bottom|Full" },
{ "gearsystem_overscan", "Overscan; Disabled|Top+Bottom|Full (284 width)|Full (320 width)" },
{ "gearcoleco_up_down_allowed", "Allow Up+Down / Left+Right; Disabled|Enabled" },
{ "gearcoleco_no_sprite_limit", "No Sprite Limit; Disabled|Enabled" },
{ "gearcoleco_spinners", "Spinner support; Disabled|Super Action Controller|Wheel Controller|Roller Controller" },
Expand Down Expand Up @@ -128,7 +128,7 @@ void retro_init(void)
core->Init(GC_PIXEL_RGB565);
#endif

frame_buffer = new u8[GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN * 2];
frame_buffer = new u8[GC_RESOLUTION_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_HEIGHT_WITH_OVERSCAN * 2];

audio_sample_count = 0;

Expand Down Expand Up @@ -235,8 +235,8 @@ void retro_get_system_av_info(struct retro_system_av_info *info)

info->geometry.base_width = runtime_info.screen_width;
info->geometry.base_height = runtime_info.screen_height;
info->geometry.max_width = GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN;
info->geometry.max_height = GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN;
info->geometry.max_width = GC_RESOLUTION_WIDTH_WITH_OVERSCAN;
info->geometry.max_height = GC_RESOLUTION_HEIGHT_WITH_OVERSCAN;
info->geometry.aspect_ratio = aspect_ratio;
info->timing.fps = runtime_info.region == Region_NTSC ? 60.0 : 50.0;
info->timing.sample_rate = 44100.0;
Expand Down Expand Up @@ -516,8 +516,10 @@ static void check_variables(void)
core->GetVideo()->SetOverscan(Video::OverscanDisabled);
else if (strcmp(var.value, "Top+Bottom") == 0)
core->GetVideo()->SetOverscan(Video::OverscanTopBottom);
else if (strcmp(var.value, "Full") == 0)
core->GetVideo()->SetOverscan(Video::OverscanFull);
else if (strcmp(var.value, "Full (284 width)") == 0)
core->GetVideo()->SetOverscan(Video::OverscanFull284);
else if (strcmp(var.value, "Full (320 width)") == 0)
core->GetVideo()->SetOverscan(Video::OverscanFull320);
else
core->GetVideo()->SetOverscan(Video::OverscanDisabled);
}
Expand Down
14 changes: 8 additions & 6 deletions src/GearcolecoCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,18 @@ void GearcolecoCore::SaveDisassembledROM()

bool GearcolecoCore::GetRuntimeInfo(GC_RuntimeInfo& runtime_info)
{
runtime_info.screen_width = GC_RESOLUTION_MAX_WIDTH;
runtime_info.screen_height = GC_RESOLUTION_MAX_HEIGHT;
runtime_info.screen_width = GC_RESOLUTION_WIDTH;
runtime_info.screen_height = GC_RESOLUTION_HEIGHT;
runtime_info.region = Region_NTSC;

if (m_pCartridge->IsReady())
{
if (m_pVideo->GetOverscan() == Video::OverscanFull)
runtime_info.screen_width = GC_RESOLUTION_MAX_WIDTH + (2 * GC_RESOLUTION_OVERSCAN_H);
if (m_pVideo->GetOverscan() == Video::OverscanFull284)
runtime_info.screen_width = GC_RESOLUTION_WIDTH + GC_RESOLUTION_SMS_OVERSCAN_H_284_L + GC_RESOLUTION_SMS_OVERSCAN_H_284_R;
if (m_pVideo->GetOverscan() == Video::OverscanFull320)
runtime_info.screen_width = GC_RESOLUTION_WIDTH + GC_RESOLUTION_SMS_OVERSCAN_H_320_L + GC_RESOLUTION_SMS_OVERSCAN_H_320_R;
if (m_pVideo->GetOverscan() != Video::OverscanDisabled)
runtime_info.screen_height = GC_RESOLUTION_MAX_HEIGHT + (2 * (m_pCartridge->IsPAL() ? GC_RESOLUTION_OVERSCAN_V_PAL : GC_RESOLUTION_OVERSCAN_V));
runtime_info.screen_height = GC_RESOLUTION_HEIGHT + (2 * (m_pCartridge->IsPAL() ? GC_RESOLUTION_OVERSCAN_V_PAL : GC_RESOLUTION_OVERSCAN_V));
runtime_info.region = m_pCartridge->IsPAL() ? Region_PAL : Region_NTSC;
return true;
}
Expand Down Expand Up @@ -589,7 +591,7 @@ void GearcolecoCore::Reset()

void GearcolecoCore::RenderFrameBuffer(u8* finalFrameBuffer)
{
int size = GC_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN;
int size = GC_RESOLUTION_WIDTH_WITH_OVERSCAN * GC_RESOLUTION_HEIGHT_WITH_OVERSCAN;
u16* srcBuffer = (m_pMemory->IsBiosLoaded() ? m_pVideo->GetFrameBuffer() : kNoBiosImage);

switch (m_pixelFormat)
Expand Down
Loading

0 comments on commit c917c95

Please sign in to comment.