Skip to content

Commit

Permalink
Add Overscan options. Fixes #68, fixes #64.
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 9, 2024
1 parent 7506763 commit 5383677
Show file tree
Hide file tree
Showing 11 changed files with 392 additions and 116 deletions.
12 changes: 7 additions & 5 deletions platforms/desktop-shared/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ void config_read(void)
config_emulator.savestates_dir_option = read_int("Emulator", "SaveStatesDirOption", 0);
config_emulator.savestates_path = read_string("Emulator", "SaveStatesPath");
config_emulator.last_open_path = read_string("Emulator", "LastOpenPath");
config_emulator.window_width = read_int("Emulator", "WindowWidth", 770);
config_emulator.window_height = read_int("Emulator", "WindowHeight", 600);
config_emulator.window_width = read_int("Emulator", "WindowWidth", 640);
config_emulator.window_height = read_int("Emulator", "WindowHeight", 503);

if (config_emulator.savefiles_path.empty())
{
Expand All @@ -214,13 +214,14 @@ void config_read(void)
}

config_video.scale = read_int("Video", "Scale", 0);
config_video.ratio = read_int("Video", "AspectRatio", 0);
config_video.ratio = read_int("Video", "AspectRatio", 1);
config_video.overscan = read_int("Video", "Overscan", 1);
config_video.fps = read_bool("Video", "FPS", false);
config_video.bilinear = read_bool("Video", "Bilinear", false);
config_video.mix_frames = read_bool("Video", "MixFrames", true);
config_video.mix_frames_intensity = read_float("Video", "MixFramesIntensity", 0.30f);
config_video.mix_frames_intensity = read_float("Video", "MixFramesIntensity", 0.10f);
config_video.scanlines = read_bool("Video", "Scanlines", true);
config_video.scanlines_intensity = read_float("Video", "ScanlinesIntensity", 0.40f);
config_video.scanlines_intensity = read_float("Video", "ScanlinesIntensity", 0.10f);
config_video.sync = read_bool("Video", "Sync", true);
config_video.glasses = read_int("Video", "3DGlasses", 0);

Expand Down Expand Up @@ -308,6 +309,7 @@ void config_write(void)

write_int("Video", "Scale", config_video.scale);
write_int("Video", "AspectRatio", config_video.ratio);
write_int("Video", "Overscan", config_video.overscan);
write_bool("Video", "FPS", config_video.fps);
write_bool("Video", "Bilinear", config_video.bilinear);
write_bool("Video", "MixFrames", config_video.mix_frames);
Expand Down
11 changes: 6 additions & 5 deletions platforms/desktop-shared/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,20 +60,21 @@ struct config_Emulator
int savestates_dir_option = 0;
std::string savestates_path;
std::string last_open_path;
int window_width = 770;
int window_height = 600;
int window_width = 640;
int window_height = 503;
};

struct config_Video
{
int scale = 0;
int ratio = 0;
int ratio = 1;
int overscan = 1;
bool fps = false;
bool bilinear = false;
bool mix_frames = true;
float mix_frames_intensity = 0.30f;
float mix_frames_intensity = 0.10f;
bool scanlines = true;
float scanlines_intensity = 0.40f;
float scanlines_intensity = 0.10f;
bool sync = true;
int glasses = 0;
};
Expand Down
26 changes: 20 additions & 6 deletions platforms/desktop-shared/emu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ static bool debugging = false;
static bool debug_step = false;
static bool debug_next_frame = false;

u16* frame_buffer;
u16* debug_background_buffer;
u16* debug_tile_buffer;
u16* debug_sprite_buffers[64];
Expand All @@ -52,14 +51,12 @@ static void update_debug_sprite_buffers_sg1000(void);

void emu_init(void)
{
int screen_size = GS_RESOLUTION_MAX_WIDTH * GS_RESOLUTION_MAX_HEIGHT;
int screen_size = GS_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN * GS_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN;

emu_frame_buffer = new u8[screen_size * 3];
frame_buffer = new u16[screen_size];


for (int i=0, j=0; i < screen_size; i++, j+=3)
{
frame_buffer[i] = 0;
emu_frame_buffer[j] = 0;
emu_frame_buffer[j+1] = 0;
emu_frame_buffer[j+2] = 0;
Expand Down Expand Up @@ -96,7 +93,6 @@ void emu_destroy(void)
SafeDelete(sound_queue);
SafeDelete(gearsystem);
SafeDeleteArray(emu_frame_buffer);
SafeDeleteArray(frame_buffer);
destroy_debug();
}

Expand Down Expand Up @@ -376,6 +372,24 @@ void emu_set_3d_glasses_config(int config)
gearsystem->SetGlassesConfig(glasses);
}

void emu_set_overscan(int overscan)
{
switch (overscan)
{
case 0:
gearsystem->GetVideo()->SetOverscan(Video::OverscanDisabled);
break;
case 1:
gearsystem->GetVideo()->SetOverscan(Video::OverscanTopBottom);
break;
case 2:
gearsystem->GetVideo()->SetOverscan(Video::OverscanFull);
break;
default:
gearsystem->GetVideo()->SetOverscan(Video::OverscanDisabled);
}
}

static void save_ram(void)
{
#ifdef DEBUG_GEARSYSTEM
Expand Down
1 change: 1 addition & 0 deletions platforms/desktop-shared/emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ EXTERN void emu_enable_bootrom_sms(bool enable);
EXTERN void emu_enable_bootrom_gg(bool enable);
EXTERN void emu_set_media_slot(int slot);
EXTERN void emu_set_3d_glasses_config(int config);
EXTERN void emu_set_overscan(int overscan);

#undef EMU_IMPORT
#undef EXTERN
Expand Down
25 changes: 20 additions & 5 deletions platforms/desktop-shared/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void gui_init(void)
emu_enable_bootrom_sms(config_emulator.sms_bootrom);
emu_enable_bootrom_gg(config_emulator.gg_bootrom);
emu_set_media_slot(config_emulator.media);
emu_set_overscan(config_video.overscan);
}

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

for (int i=0; i < (GS_RESOLUTION_MAX_WIDTH * GS_RESOLUTION_MAX_HEIGHT); i++)
for (int i=0; i < (GS_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN * GS_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN); i++)
{
emu_frame_buffer[i] = 0;
}
Expand Down Expand Up @@ -640,8 +641,19 @@ static void main_menu(void)

if (ImGui::BeginMenu("Aspect Ratio"))
{
ImGui::PushItemWidth(160.0f);
ImGui::Combo("##ratio", &config_video.ratio, "Square Pixels\0Standard (4:3)\0Wide (16:9)\0Fit Content to Window\0\0");
ImGui::PushItemWidth(200.0f);
ImGui::Combo("##ratio", &config_video.ratio, "Square Pixels (1:1 PAR)\0Standard (4:3 PAR)\0Wide (16:9 PAR)\0Fit Content to Window\0\0");
ImGui::PopItemWidth();
ImGui::EndMenu();
}

if (ImGui::BeginMenu("Overscan"))
{
ImGui::PushItemWidth(120.0f);
if (ImGui::Combo("##overscan", &config_video.overscan, "Disabled\0Top+Bottom\0Full\0\0"))
{
emu_set_overscan(config_video.overscan);
}
ImGui::PopItemWidth();
ImGui::EndMenu();
}
Expand Down Expand Up @@ -1076,7 +1088,10 @@ static void main_window(void)
gui_main_window_hovered = ImGui::IsWindowHovered();
}

ImGui::Image((void*)(intptr_t)renderer_emu_texture, ImVec2((float)main_window_width, (float)main_window_height));
float tex_h = (float)runtime.screen_width / (float)(GS_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN);
float tex_v = (float)runtime.screen_height / (float)(GS_RESOLUTION_MAX_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));

if (config_video.fps)
show_fps();
Expand Down Expand Up @@ -1451,7 +1466,7 @@ static void menu_reset(void)
{
emu_pause();

for (int i=0; i < (GS_RESOLUTION_MAX_WIDTH * GS_RESOLUTION_MAX_HEIGHT); i++)
for (int i=0; i < (GS_RESOLUTION_MAX_WIDTH_WITH_OVERSCAN * GS_RESOLUTION_MAX_HEIGHT_WITH_OVERSCAN); i++)
{
emu_frame_buffer[i] = 0;
}
Expand Down
Loading

0 comments on commit 5383677

Please sign in to comment.