Skip to content

Commit

Permalink
Added test input for keyboard and start screen option
Browse files Browse the repository at this point in the history
  • Loading branch information
zoltanvb committed Mar 29, 2024
1 parent 30e01cf commit b51e5cf
Showing 1 changed file with 50 additions and 13 deletions.
63 changes: 50 additions & 13 deletions cores/libretro-net-retropad/net_retropad_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#define MAX_TEST_STEPS 200
#define INITIAL_FRAMES 60*5
#define ONE_TEST_STEP_FRAMES 60*5

#define KEYBOARD_OFFSET 1000
#define NETRETROPAD_SCREEN_PAD 0
#define NETRETROPAD_SCREEN_KEYBOARD 1

Expand Down Expand Up @@ -491,11 +491,25 @@ static void NETRETROPAD_CORE_PREFIX(update_keyboard_cb)(bool down, unsigned keyc
keyboard_state[keycode] = down ? true : false;
if (down && ((keycode == RETROK_a && keyboard_state[RETROK_b]) || (keycode == RETROK_b && keyboard_state[RETROK_a])))
flip_screen();
/* TODO: message only for the bottom blocks, with key name */
snprintf(buf, sizeof(buf), "Key pressed: %d",keycode);
/* Message for the keypresses not shown as actual keys, just placeholder blocks */
if ((keycode == 0) ||
(keycode == 12) ||
(keycode >= 33 && keycode < 39) ||
(keycode >= 40 && keycode < 44) ||
(keycode == 58) ||
(keycode == 60) ||
(keycode >= 62 && keycode < 65) ||
(keycode >= 94 && keycode < 96) ||
(keycode >= 123 && keycode < 127) ||
(keycode == 272) ||
(keycode >= 294 && keycode < 297) ||
(keycode >= 309 && keycode < 323))
{
snprintf(buf, sizeof(buf), "Key pressed: %d",keycode);
message.msg = buf;
message.frames = 60;
NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &message);
}
}
}

Expand Down Expand Up @@ -569,7 +583,7 @@ void NETRETROPAD_CORE_PREFIX(retro_set_environment)(retro_environment_t cb)
{ "net_retropad_ip_octet2", "IP address part 2; 0|1|2|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|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165|166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184|185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240|241|242|243|244|245|246|247|248|249|250|251|252|253|254|255" },
{ "net_retropad_ip_octet3", "IP address part 3; 0|1|2|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|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165|166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184|185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240|241|242|243|244|245|246|247|248|249|250|251|252|253|254|255" },
{ "net_retropad_ip_octet4", "IP address part 4; 0|1|2|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|31|32|33|34|35|36|37|38|39|40|41|42|43|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|71|72|73|74|75|76|77|78|79|80|81|82|83|84|85|86|87|88|89|90|91|92|93|94|95|96|97|98|99|100|101|102|103|104|105|106|107|108|109|110|111|112|113|114|115|116|117|118|119|120|121|122|123|124|125|126|127|128|129|130|131|132|133|134|135|136|137|138|139|140|141|142|143|144|145|146|147|148|149|150|151|152|153|154|155|156|157|158|159|160|161|162|163|164|165|166|167|168|169|170|171|172|173|174|175|176|177|178|179|180|181|182|183|184|185|186|187|188|189|190|191|192|193|194|195|196|197|198|199|200|201|202|203|204|205|206|207|208|209|210|211|212|213|214|215|216|217|218|219|220|221|222|223|224|225|226|227|228|229|230|231|232|233|234|235|236|237|238|239|240|241|242|243|244|245|246|247|248|249|250|251|252|253|254|255" },

{ "net_retropad_screen", "Start screen; Retropad|Keyboard tester" },
{ NULL, NULL },
};
enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565;
Expand All @@ -592,21 +606,27 @@ void NETRETROPAD_CORE_PREFIX(retro_set_environment)(retro_environment_t cb)

static void netretropad_check_variables(void)
{
struct retro_variable var, var2, var3, var4, port_var;
var.key = "net_retropad_ip_octet1";
var2.key = "net_retropad_ip_octet2";
var3.key = "net_retropad_ip_octet3";
var4.key = "net_retropad_ip_octet4";
port_var.key = "net_retropad_port";
struct retro_variable var, var2, var3, var4, port_var, screen_var;
var.key = "net_retropad_ip_octet1";
var2.key = "net_retropad_ip_octet2";
var3.key = "net_retropad_ip_octet3";
var4.key = "net_retropad_ip_octet4";
port_var.key = "net_retropad_port";
screen_var.key = "net_retropad_screen";

NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &var2);
NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &var3);
NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &var4);
NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &port_var);
NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_GET_VARIABLE, &screen_var);

snprintf(server, sizeof(server), "%s.%s.%s.%s", var.value, var2.value, var3.value, var4.value);
port = atoi(port_var.value);
if( screen_var.value &&
((current_screen == NETRETROPAD_SCREEN_PAD && strstr(screen_var.value,"Keyboard")) ||
(current_screen == NETRETROPAD_SCREEN_KEYBOARD && strstr(screen_var.value,"Retropad"))))
flip_screen();
}

void NETRETROPAD_CORE_PREFIX(retro_set_audio_sample)(retro_audio_sample_t cb)
Expand Down Expand Up @@ -721,6 +741,9 @@ void NETRETROPAD_CORE_PREFIX(retro_run)(void)
NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_INFO,
"[Remote RetroPad]: Proceeding to test step %d at frame %d, next: %d\n",
current_test_step,current_frame,next_teststep_frame+INITIAL_FRAMES);
if((input_test_steps[current_test_step].expected_button < KEYBOARD_OFFSET && current_screen == NETRETROPAD_SCREEN_KEYBOARD) ||
(input_test_steps[current_test_step].expected_button >= KEYBOARD_OFFSET && current_screen == NETRETROPAD_SCREEN_PAD))
flip_screen();
}
else
{
Expand All @@ -745,8 +768,20 @@ void NETRETROPAD_CORE_PREFIX(retro_run)(void)

if (current_test_step < last_test_step)
{
expected_input = 1 << input_test_steps[current_test_step].expected_button;
if(input_state & expected_input)
bool test_success = false;
if (input_test_steps[current_test_step].expected_button < KEYBOARD_OFFSET)
{
expected_input = 1 << input_test_steps[current_test_step].expected_button;
if(input_state & expected_input)
test_success = true;
}
else
{
expected_input = input_test_steps[current_test_step].expected_button - KEYBOARD_OFFSET;
if (expected_input < RETROK_LAST && keyboard_state[expected_input])
test_success = true;
}
if (test_success)
{
NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_INFO,
"[Remote RetroPad]: Test step %d successful at frame %d\n",
Expand Down Expand Up @@ -850,7 +885,9 @@ void NETRETROPAD_CORE_PREFIX(retro_run)(void)
}
else
{
if (keyboard_state_validated[keyboard_buttons[rle]])
if (expected_input == keyboard_buttons[rle])
color = 0x7fff;
else if (keyboard_state_validated[keyboard_buttons[rle]])
color = 0xbff7;
else
color = 0xffff;
Expand Down

0 comments on commit b51e5cf

Please sign in to comment.