Skip to content

Commit 43edc8c

Browse files
committed
Error codes are now also reported with messages, detailed codes added.
1 parent ce4b31b commit 43edc8c

File tree

3 files changed

+150
-46
lines changed

3 files changed

+150
-46
lines changed

cores/libretro-net-retropad/net_retropad_core.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ static bool input_test_file_read(const char* file_path)
394394
(int)rjson_get_source_line(parser),
395395
(int)rjson_get_source_column(parser),
396396
(*rjson_get_error(parser) ? rjson_get_error(parser) : "format error"));
397+
if (last_test_step > MAX_TEST_STEPS)
398+
last_test_step = 0;
397399
}
398400

399401
/* Free parser */
@@ -412,6 +414,12 @@ static bool input_test_file_read(const char* file_path)
412414
{
413415
NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_WARN,"[Remote RetroPad]: too long test input json, maximum size: %d\n",MAX_TEST_STEPS);
414416
}
417+
if (last_test_step == 0)
418+
{
419+
NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_WARN,"[Remote RetroPad]: no steps in input json\n");
420+
success = false;
421+
}
422+
415423
for (current_test_step = 0; current_test_step < last_test_step; current_test_step++)
416424
{
417425
NETRETROPAD_CORE_PREFIX(log_cb)(RETRO_LOG_DEBUG,
@@ -564,7 +572,7 @@ unsigned NETRETROPAD_CORE_PREFIX(retro_api_version)(void)
564572
void NETRETROPAD_CORE_PREFIX(retro_set_controller_port_device)(
565573
unsigned port, unsigned device)
566574
{
567-
const char msg[] = "Device type change is not supported!";
575+
const char msg[] = "Input device type change is not supported!";
568576
struct retro_error_message e;
569577
e.code = RETROE_UNSUPPORTED_ACTION | ((port & 0xFF) << 8) | (device & 0xFF);
570578
e.message = msg;
@@ -1392,13 +1400,16 @@ void NETRETROPAD_CORE_PREFIX(retro_run)(void)
13921400

13931401
bool NETRETROPAD_CORE_PREFIX(retro_load_game)(const struct retro_game_info *info)
13941402
{
1403+
bool load_result = true;
1404+
13951405
netretropad_check_variables();
13961406
open_UDP_socket();
13971407

13981408
/* If a .ratst file is given (only possible via command line),
13991409
* initialize test sequence. */
14001410
if (info)
1401-
input_test_file_read(info->path);
1411+
load_result = input_test_file_read(info->path);
1412+
14021413
if (last_test_step > MAX_TEST_STEPS)
14031414
current_test_step = last_test_step;
14041415
else
@@ -1409,7 +1420,25 @@ bool NETRETROPAD_CORE_PREFIX(retro_load_game)(const struct retro_game_info *info
14091420
NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_MESSAGE, &message);
14101421
}
14111422

1412-
return true;
1423+
if (!load_result)
1424+
{
1425+
const char msg[] = "Invalid test input file!";
1426+
struct retro_error_message e;
1427+
e.code = RETROE_UNSUPPORTED_CONTENT_FORMAT;
1428+
e.message = msg;
1429+
NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_ERROR_CODE, &e);
1430+
}
1431+
1432+
if (false)
1433+
{
1434+
const char msg[] = "Simulated load error - BIOS!";
1435+
struct retro_error_message e;
1436+
e.code = RETROE_MISSING_BIOS | 0x4321;
1437+
e.message = msg;
1438+
NETRETROPAD_CORE_PREFIX(environ_cb)(RETRO_ENVIRONMENT_SET_ERROR_CODE, &e);
1439+
load_result = false;
1440+
}
1441+
return load_result;
14131442
}
14141443

14151444
void NETRETROPAD_CORE_PREFIX(retro_unload_game)(void) { }

libretro-common/include/libretro.h

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -711,15 +711,48 @@ enum retro_mod
711711
RETROKMOD_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
712712
};
713713

714-
/* Error codes that can be reported by the core. */
714+
/**
715+
* Error code ranges and specific errors that may be reported by cores.
716+
* Explicitly listed errors within a range may have localized error
717+
* messages maintained by the frontend. The first item in the range
718+
* acts as a generic error indication for that kind of error.
719+
* @see RETRO_ENVIRONMENT_SET_ERROR_CODE
720+
*/
715721
enum retro_error
716722
{
717723
RETROE_NONE = 0x00000000,
718724

719-
RETROE_UNSUPPORTED_CONTENT_FORMAT = 0x00010000,
720-
RETROE_MISSING_BIOS = 0x00020000,
721-
RETROE_HARDWARE_RENDERING_NOT_AVAILABLE = 0x00030000,
722-
RETROE_UNSUPPORTED_ACTION = 0x00040000,
725+
RETROE_UNSUPPORTED_CONTENT = 0x01000000,
726+
RETROE_UNSUPPORTED_CONTENT_ISO_FORMAT_ERROR = 0x01010000,
727+
RETROE_UNSUPPORTED_CONTENT_CHD_FORMAT_ERROR = 0x01020000,
728+
RETROE_UNSUPPORTED_CONTENT_CUE_FORMAT_ERROR = 0x01030000,
729+
RETROE_UNSUPPORTED_CONTENT_BIN_FORMAT_ERROR = 0x01040000,
730+
RETROE_UNSUPPORTED_CONTENT_ZIP_FORMAT_ERROR = 0x01050000,
731+
RETROE_UNSUPPORTED_CONTENT_7Z_FORMAT_ERROR = 0x01060000,
732+
RETROE_UNSUPPORTED_CONTENT_FORMAT = 0x01100000,
733+
RETROE_UNSUPPORTED_CONTENT_RANGE_END = 0x01FFFFFF,
734+
RETROE_MISSING_BIOS = 0x02000000,
735+
RETROE_MISSING_BIOS_REGION_PAL = 0x02010000,
736+
RETROE_MISSING_BIOS_REGION_NTSC = 0x02020000,
737+
RETROE_MISSING_BIOS_REGION_WORLD = 0x02030000,
738+
RETROE_MISSING_BIOS_REGION_COUNTRY = 0x02030000,
739+
RETROE_MISSING_BIOS_RANGE_END = 0x02FFFFFF,
740+
RETROE_HARDWARE_RENDERING = 0x03000000,
741+
RETROE_HARDWARE_RENDERING_VULKAN_NOT_AVAILABLE = 0x03010000,
742+
RETROE_HARDWARE_RENDERING_VULKAN_VERSION_ERROR = 0x03020000,
743+
RETROE_HARDWARE_RENDERING_OPENGL_NOT_AVAILABLE = 0x03030000,
744+
RETROE_HARDWARE_RENDERING_OPENGL_VERSION_ERROR = 0x03040000,
745+
RETROE_HARDWARE_RENDERING_DX11_NOT_AVAILABLE = 0x03050000,
746+
RETROE_HARDWARE_RENDERING_DX12_NOT_AVAILABLE = 0x03060000,
747+
RETROE_HARDWARE_RENDERING_PXFMT_XRGB8888_UNSUPP = 0x03110000,
748+
RETROE_HARDWARE_RENDERING_PXFMT_RGB565_UNSUPP = 0x03120000,
749+
RETROE_HARDWARE_RENDERING_RANGE_END = 0x03FFFFFF,
750+
RETROE_UNSUPPORTED_ACTION = 0x04000000,
751+
RETROE_UNSUPPORTED_ACTION_SERIALIZE = 0x04010000,
752+
RETROE_UNSUPPORTED_ACTION_UNSERIALIZE = 0x04020000,
753+
RETROE_UNSUPPORTED_ACTION_UNSERIALIZE_FORMAT = 0x04030000,
754+
RETROE_UNSUPPORTED_ACTION_CORE_OPTION_COMBI = 0x04040000,
755+
RETROE_UNSUPPORTED_ACTION_RANGE_END = 0x04FFFFFF,
723756

724757
RETROE_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
725758
};

0 commit comments

Comments
 (0)