Skip to content

Commit 070cce1

Browse files
committed
Add turbo I and II to controllers. Fix #21
1 parent 7772c77 commit 070cce1

File tree

11 files changed

+239
-11
lines changed

11 files changed

+239
-11
lines changed

platforms/libretro/libretro.cpp

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -591,25 +591,44 @@ static void update_input(void)
591591
static void set_variabless(void)
592592
{
593593
struct retro_variable vars[] = {
594-
{ "geargrafx_turbotap", "TurboTap; Disabled|Enabled" },
594+
{ "geargrafx_console_type", "System (restart); Auto|PC Engine (JAP)|SuperGrafx (JAP)|TurboGrafx-16 (USA)" },
595595
{ "geargrafx_aspect_ratio", "Aspect Ratio; 1:1 PAR|4:3 DAR|6:5 DAR|16:9 DAR|16:10 DAR" },
596596
{ "geargrafx_overscan", "Overscan; Disabled|Enabled" },
597597
{ "geargrafx_scanline_count", "Scanline Count; 224p|240p|Manual" },
598598
{ "geargrafx_scanline_start", "Scanline Start (Manual); 3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|0|1|2" },
599599
{ "geargrafx_scanline_end", "Scanline End (Manual); 241|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240" },
600600
{ "geargrafx_composite_colors", "Composite Colors; Disabled|Enabled" },
601+
{ "geargrafx_no_sprite_limit", "No Sprite Limit; Disabled|Enabled" },
601602
{ "geargrafx_backup_ram", "Backup RAM (restart); Enabled|Disabled" },
602-
{ "geargrafx_console_type", "System (restart); Auto|PC Engine (JAP)|SuperGrafx (JAP)|TurboGrafx-16 (USA)" },
603603
{ "geargrafx_cdrom_type", "CD-ROM (restart); Auto|Standard|Super CD-ROM|Arcade CD-ROM" },
604604
{ "geargrafx_cdrom_bios", "CD-ROM Bios; Auto|System Card 1|System Card 2|System Card 3|Game Express" },
605605
{ "geargrafx_cdrom_preload", "Preload CD-ROM (restart); Disabled|Enabled" },
606-
{ "geargrafx_no_sprite_limit", "No Sprite Limit; Disabled|Enabled" },
607-
{ "geargrafx_avenue_pad_3_switch", "Avenue Pad 3 Switch; Auto|SELECT|RUN" },
608-
{ "geargrafx_soft_reset", "Soft Reset; Enabled|Disabled" },
609-
{ "geargrafx_up_down_allowed", "Allow Up+Down / Left+Right; Disabled|Enabled" },
610606
{ "geargrafx_psg_volume", "PSG Volume; 100|0|10|20|30|40|50|60|70|80|90|100|110|120|130|140|150|160|170|180|190|200" },
611607
{ "geargrafx_cdrom_volume", "CD-ROM Volume; 100|0|10|20|30|40|50|60|70|80|90|100|110|120|130|140|150|160|170|180|190|200" },
612608
{ "geargrafx_adpcm_volume", "ADPCM Volume; 100|0|10|20|30|40|50|60|70|80|90|100|110|120|130|140|150|160|170|180|190|200" },
609+
{ "geargrafx_up_down_allowed", "Allow Up+Down / Left+Right; Disabled|Enabled" },
610+
{ "geargrafx_soft_reset", "Allow Soft Reset; Enabled|Disabled" },
611+
{ "geargrafx_turbotap", "TurboTap; Disabled|Enabled" },
612+
{ "geargrafx_avenue_pad_3_switch", "Avenue Pad 3 Switch; Auto|SELECT|RUN" },
613+
{ "geargrafx_turbo_p1_i", "P1 Turbo I; Disabled|Enabled" },
614+
{ "geargrafx_turbo_p2_i", "P2 Turbo I; Disabled|Enabled" },
615+
{ "geargrafx_turbo_p2_ii", "P2 Turbo II; Disabled|Enabled" },
616+
{ "geargrafx_turbo_p3_i", "P3 Turbo I; Disabled|Enabled" },
617+
{ "geargrafx_turbo_p3_ii", "P3 Turbo II; Disabled|Enabled" },
618+
{ "geargrafx_turbo_p4_i", "P4 Turbo I; Disabled|Enabled" },
619+
{ "geargrafx_turbo_p4_ii", "P4 Turbo II; Disabled|Enabled" },
620+
{ "geargrafx_turbo_p5_i", "P5 Turbo I; Disabled|Enabled" },
621+
{ "geargrafx_turbo_p5_ii", "P5 Turbo II; Disabled|Enabled" },
622+
{ "geargrafx_turbo_speed_p1_i", "P1 Turbo I Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
623+
{ "geargrafx_turbo_speed_p1_ii", "P1 Turbo II Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
624+
{ "geargrafx_turbo_speed_p2_i", "P2 Turbo I Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
625+
{ "geargrafx_turbo_speed_p2_ii", "P2 Turbo II Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
626+
{ "geargrafx_turbo_speed_p3_i", "P3 Turbo I Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
627+
{ "geargrafx_turbo_speed_p3_ii", "P3 Turbo II Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
628+
{ "geargrafx_turbo_speed_p4_i", "P4 Turbo I Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
629+
{ "geargrafx_turbo_speed_p4_ii", "P4 Turbo II Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
630+
{ "geargrafx_turbo_speed_p5_i", "P5 Turbo I Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
631+
{ "geargrafx_turbo_speed_p5_ii", "P5 Turbo II Speed; 4|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15" },
613632
{ NULL }
614633
};
615634

@@ -862,4 +881,52 @@ static void check_variables(void)
862881
float volume_f = (float)volume / 100.0f;
863882
core->GetAudio()->SetADPCMVolume(volume_f);
864883
}
884+
885+
for (int i = 0; i < 5; i++)
886+
{
887+
char key[64];
888+
snprintf(key, sizeof(key), "geargrafx_turbo_p%d_i", i + 1);
889+
var.key = key;
890+
var.value = NULL;
891+
892+
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
893+
{
894+
bool enabled = (strcmp(var.value, "Enabled") == 0);
895+
core->GetInput()->EnableTurbo((GG_Controllers)i, GG_KEY_I, enabled);
896+
}
897+
898+
snprintf(key, sizeof(key), "geargrafx_turbo_p%d_ii", i + 1);
899+
var.key = key;
900+
var.value = NULL;
901+
902+
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
903+
{
904+
bool enabled = (strcmp(var.value, "Enabled") == 0);
905+
core->GetInput()->EnableTurbo((GG_Controllers)i, GG_KEY_II, enabled);
906+
}
907+
908+
snprintf(key, sizeof(key), "geargrafx_turbo_speed_p%d_i", i + 1);
909+
var.key = key;
910+
var.value = NULL;
911+
912+
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
913+
{
914+
int speed = atoi(var.value);
915+
if (speed < 0)
916+
speed = 1;
917+
core->GetInput()->SetTurboSpeed((GG_Controllers)i, GG_KEY_I, speed);
918+
}
919+
920+
snprintf(key, sizeof(key), "geargrafx_turbo_speed_p%d_ii", i + 1);
921+
var.key = key;
922+
var.value = NULL;
923+
924+
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
925+
{
926+
int speed = atoi(var.value);
927+
if (speed < 0)
928+
speed = 1;
929+
core->GetInput()->SetTurboSpeed((GG_Controllers)i, GG_KEY_II, speed);
930+
}
931+
}
865932
}

platforms/shared/desktop/config.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ void config_init(void)
100100
{
101101
config_input.controller_type[i] = 0;
102102
config_input.avenue_pad_3_button[i] = 0;
103+
for (int j = 0; j < 2; j++)
104+
{
105+
config_input.turbo_enabled[i][j] = false;
106+
config_input.turbo_speed[i][j] = 4;
107+
}
103108

104109
config_input_gamepad[i].detected = false;
105110
config_input_gamepad[i].gamepad_invert_x_axis = false;
@@ -267,6 +272,13 @@ void config_read(void)
267272
snprintf(input_group, sizeof(input_group), "Input%d", i + 1);
268273
config_input.controller_type[i] = read_int(input_group, "ControllerType", 0);
269274
config_input.avenue_pad_3_button[i] = read_int(input_group, "AvenuePad3Button", 0);
275+
for (int j = 0; j < 2; j++)
276+
{
277+
char turbo_group[32];
278+
snprintf(turbo_group, sizeof(turbo_group), "Turbo%d", j + 1);
279+
config_input.turbo_enabled[i][j] = read_bool(input_group, turbo_group, false);
280+
config_input.turbo_speed[i][j] = read_int(input_group, turbo_group, 4);
281+
}
270282
}
271283

272284
config_input_keyboard[0].key_left = (SDL_Scancode)read_int("InputKeyboard1", "KeyLeft", SDL_SCANCODE_LEFT);
@@ -450,6 +462,13 @@ void config_write(void)
450462
snprintf(input_group, sizeof(input_group), "Input%d", i + 1);
451463
write_int(input_group, "ControllerType", config_input.controller_type[i]);
452464
write_int(input_group, "AvenuePad3Button", config_input.avenue_pad_3_button[i]);
465+
for (int j = 0; j < 2; j++)
466+
{
467+
char turbo_group[32];
468+
snprintf(turbo_group, sizeof(turbo_group), "Turbo%d", j + 1);
469+
write_bool(input_group, turbo_group, config_input.turbo_enabled[i][j]);
470+
write_int(input_group, turbo_group, config_input.turbo_speed[i][j]);
471+
}
453472
}
454473

455474
write_int("InputKeyboard1", "KeyLeft", config_input_keyboard[0].key_left);

platforms/shared/desktop/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ struct config_Input
101101
bool turbo_tap = false;
102102
int controller_type[GG_MAX_GAMEPADS];
103103
int avenue_pad_3_button[GG_MAX_GAMEPADS];
104+
bool turbo_enabled[GG_MAX_GAMEPADS][2];
105+
int turbo_speed[GG_MAX_GAMEPADS][2];
104106
};
105107

106108
struct config_Input_Keyboard

platforms/shared/desktop/emu.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,19 @@ void emu_set_avenue_pad_3_button(GG_Controllers controller, GG_Keys button)
463463
geargrafx->GetInput()->SetAvenuePad3Button(controller, button);
464464
}
465465

466+
void emu_set_turbo(GG_Controllers controller, GG_Keys button, bool enabled)
467+
{
468+
geargrafx->GetInput()->EnableTurbo(controller, button, enabled);
469+
}
470+
471+
void emu_set_turbo_speed(GG_Controllers controller, GG_Keys button, u8 speed)
472+
{
473+
if (speed < 0)
474+
speed = 1;
475+
476+
geargrafx->GetInput()->SetTurboSpeed(controller, button, speed);
477+
}
478+
466479
void emu_save_screenshot(const char* file_path)
467480
{
468481
if (!geargrafx->GetMedia()->IsReady())

platforms/shared/desktop/emu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ EXTERN void emu_set_backup_ram(bool enabled);
109109
EXTERN void emu_set_turbo_tap(bool enabled);
110110
EXTERN void emu_set_pad_type(GG_Controllers controller, GG_Controller_Type type);
111111
EXTERN void emu_set_avenue_pad_3_button(GG_Controllers controller, GG_Keys button);
112+
EXTERN void emu_set_turbo(GG_Controllers controller, GG_Keys button, bool enabled);
113+
EXTERN void emu_set_turbo_speed(GG_Controllers controller, GG_Keys button, u8 speed);
112114
EXTERN void emu_save_screenshot(const char* file_path);
113115
EXTERN bool emu_load_bios(const char* file_path, bool syscard);
114116

platforms/shared/desktop/gui.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ void gui_init(void)
140140
else if (config_input.avenue_pad_3_button[i] == 2)
141141
key = GG_KEY_RUN;
142142
emu_set_avenue_pad_3_button((GG_Controllers)i, key);
143+
for (int j = 0; j < 2; j++)
144+
{
145+
emu_set_turbo((GG_Controllers)i, (GG_Keys)j, config_input.turbo_enabled[i][j]);
146+
emu_set_turbo_speed((GG_Controllers)i, (GG_Keys)j, config_input.turbo_speed[i][j]);
147+
}
143148
}
144149
emu_debug_set_callback(gui_debug_callback);
145150

platforms/shared/desktop/gui_menus.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ static void menu_input(void)
668668
ImGui::EndTooltip();
669669
}
670670

671-
if (ImGui::BeginMenu("Controller Type"))
671+
if (ImGui::BeginMenu("Controller"))
672672
{
673673
for (int i = 0; i < GG_MAX_GAMEPADS; i++)
674674
{
@@ -713,6 +713,53 @@ static void menu_input(void)
713713
ImGui::EndTooltip();
714714
}
715715
}
716+
717+
ImGui::Separator();
718+
719+
if (ImGui::MenuItem("Turbo I", "", &config_input.turbo_enabled[i][0]))
720+
{
721+
emu_set_turbo((GG_Controllers)i, GG_KEY_I, config_input.turbo_enabled[i][0]);
722+
}
723+
if (ImGui::IsItemHovered())
724+
{
725+
ImGui::BeginTooltip();
726+
ImGui::Text("Click to enable or disable Turbo I for Player %d.", i + 1);
727+
ImGui::EndTooltip();
728+
}
729+
730+
if (ImGui::SliderInt("##turbo_speed_i", &config_input.turbo_speed[i][0], 1, 20, "Turbo I Speed = %d", ImGuiSliderFlags_AlwaysClamp))
731+
{
732+
emu_set_turbo_speed((GG_Controllers)i, GG_KEY_I, config_input.turbo_speed[i][0]);
733+
}
734+
if (ImGui::IsItemHovered())
735+
{
736+
ImGui::BeginTooltip();
737+
ImGui::Text("The number of frames between each button I toggle.");
738+
ImGui::EndTooltip();
739+
}
740+
741+
if (ImGui::MenuItem("Turbo II", "", &config_input.turbo_enabled[i][1]))
742+
{
743+
emu_set_turbo((GG_Controllers)i, GG_KEY_II, config_input.turbo_enabled[i][1]);
744+
}
745+
if (ImGui::IsItemHovered())
746+
{
747+
ImGui::BeginTooltip();
748+
ImGui::Text("Click to enable or disable Turbo II for Player %d.", i + 1);
749+
ImGui::EndTooltip();
750+
}
751+
752+
if(ImGui::SliderInt("##turbo_speed_ii", &config_input.turbo_speed[i][1], 1, 20, "Turbo II Speed = %d", ImGuiSliderFlags_AlwaysClamp))
753+
{
754+
emu_set_turbo_speed((GG_Controllers)i, GG_KEY_II, config_input.turbo_speed[i][1]);
755+
}
756+
if (ImGui::IsItemHovered())
757+
{
758+
ImGui::BeginTooltip();
759+
ImGui::Text("The number of frames between each button II toggle.");
760+
ImGui::EndTooltip();
761+
}
762+
716763
ImGui::EndMenu();
717764
}
718765
}

src/geargrafx_core_inline.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ bool GeargrafxCore::RunToVBlankTemplate(u8* frame_buffer, s16* sample_buffer, in
117117
while (!stop);
118118

119119
m_audio->EndFrame(sample_buffer, sample_count);
120+
m_input->EndFrame();
120121

121122
return m_huc6280->BreakpointHit() || m_huc6280->RunToBreakpointHit();
122123
}
@@ -143,6 +144,8 @@ bool GeargrafxCore::RunToVBlankTemplate(u8* frame_buffer, s16* sample_buffer, in
143144
while (!stop);
144145

145146
m_audio->EndFrame(sample_buffer, sample_count);
147+
m_input->EndFrame();
148+
146149
return false;
147150
}
148151
}

src/input.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Input::Input(Media* media)
3939
m_avenue_pad_3_state[i] = 0xFFFF;
4040
m_gamepads[i] = 0xFFFF;
4141
m_selected_extra_buttons = false;
42+
43+
for (int j = 0; j < 2; j++)
44+
{
45+
m_turbo_enabled[i][j] = false;
46+
m_turbo_state[i][j] = false;
47+
m_turbo_counter[i][j] = 0;
48+
m_turbo_speed[i][j] = 4;
49+
}
4250
}
4351
}
4452

@@ -59,11 +67,41 @@ void Input::Reset()
5967
m_avenue_pad_3_state[i] = 0xFFFF;
6068
m_gamepads[i] = 0xFFFF;
6169
m_selected_extra_buttons = false;
70+
71+
for (int j = 0; j < 2; j++)
72+
{
73+
m_turbo_counter[i][j] = 0;
74+
m_turbo_state[i][j] = false;
75+
}
6276
}
6377

6478
UpdateRegister(0xFF);
6579
}
6680

81+
void Input::EndFrame()
82+
{
83+
for (int i = 0; i < GG_MAX_GAMEPADS; i++)
84+
{
85+
for (int j = 0; j < 2; j++)
86+
{
87+
if (m_turbo_enabled[i][j])
88+
{
89+
m_turbo_counter[i][j]++;
90+
if (m_turbo_counter[i][j] == m_turbo_speed[i][j])
91+
{
92+
m_turbo_counter[i][j] = 0;
93+
m_turbo_state[i][j] = !m_turbo_state[i][j];
94+
}
95+
}
96+
else
97+
{
98+
m_turbo_counter[i][j] = 0;
99+
m_turbo_state[i][j] = false;
100+
}
101+
}
102+
}
103+
}
104+
67105
void Input::SaveState(std::ostream& stream)
68106
{
69107
using namespace std;

src/input.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@ class Input
4141
u8 GetIORegister();
4242
bool GetSel();
4343
bool GetClr();
44+
void EndFrame();
4445
void EnablePCEJap(bool enable);
4546
void EnableCDROM(bool enable);
4647
void EnableTurboTap(bool enabled);
48+
void EnableTurbo(GG_Controllers controller, GG_Keys key, bool enabled);
49+
void SetTurboSpeed(GG_Controllers controller, GG_Keys key, u8 speed);
4750
void SetControllerType(GG_Controllers controller, GG_Controller_Type type);
4851
void SetAvenuePad3Button(GG_Controllers controller, GG_Keys button);
4952
void SaveState(std::ostream& stream);
@@ -63,6 +66,10 @@ class Input
6366
bool m_selected_extra_buttons;
6467
GG_Keys m_avenue_pad_3_button[GG_MAX_GAMEPADS];
6568
u16 m_avenue_pad_3_state[GG_MAX_GAMEPADS];
69+
bool m_turbo_enabled[GG_MAX_GAMEPADS][2];
70+
bool m_turbo_state[GG_MAX_GAMEPADS][2];
71+
u8 m_turbo_counter[GG_MAX_GAMEPADS][2];
72+
u8 m_turbo_speed[GG_MAX_GAMEPADS][2];
6673

6774
private:
6875
void UpdateRegister(u8 value);

0 commit comments

Comments
 (0)