Skip to content

Commit a7c9c4b

Browse files
committed
backport commit r4639 - add platform-independent message dialog
1 parent 848a397 commit a7c9c4b

File tree

5 files changed

+114
-13
lines changed

5 files changed

+114
-13
lines changed

libretro/libretro.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <stdarg.h>
12
#include "libretro.h"
23

34
#include "MMU.h"
@@ -15,6 +16,7 @@
1516

1617
//
1718

19+
static retro_log_printf_t log_cb = NULL;
1820
static retro_video_refresh_t video_cb = NULL;
1921
static retro_input_poll_t poll_cb = NULL;
2022
static retro_input_state_t input_cb = NULL;
@@ -251,8 +253,62 @@ void retro_get_system_av_info(struct retro_system_av_info *info)
251253
info->timing.sample_rate = 44100.0;
252254
}
253255

256+
//====================== Message box
257+
#define MSG_ARG \
258+
char msg_buf[1024] = {0}; \
259+
{ \
260+
va_list args; \
261+
va_start (args, fmt); \
262+
vsprintf (msg_buf, fmt, args); \
263+
va_end (args); \
264+
}
265+
266+
void msgWndInfo(const char *fmt, ...)
267+
{
268+
MSG_ARG;
269+
if (log_cb)
270+
log_cb(RETRO_LOG_INFO, "%s.\n", msg_buf);
271+
}
272+
273+
bool msgWndConfirm(const char *fmt, ...)
274+
{
275+
MSG_ARG;
276+
if (log_cb)
277+
log_cb(RETRO_LOG_INFO, "%s.\n", msg_buf);
278+
return true;
279+
}
280+
281+
void msgWndError(const char *fmt, ...)
282+
{
283+
MSG_ARG;
284+
if (log_cb)
285+
log_cb(RETRO_LOG_ERROR, "%s.\n", msg_buf);
286+
}
287+
288+
void msgWndWarn(const char *fmt, ...)
289+
{
290+
MSG_ARG;
291+
if (log_cb)
292+
log_cb(RETRO_LOG_WARN, "%s.\n", msg_buf);
293+
}
294+
295+
msgBoxInterface msgBoxWnd = {
296+
msgWndInfo,
297+
msgWndConfirm,
298+
msgWndError,
299+
msgWndWarn,
300+
};
301+
//====================== Dialogs end
302+
303+
254304
void retro_init (void)
255305
{
306+
struct retro_log_callback log;
307+
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))
308+
log_cb = log.log;
309+
else
310+
log_cb = NULL;
311+
256312
colorMode = RETRO_PIXEL_FORMAT_RGB565;
257313
if(!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &colorMode))
258314
colorMode = RETRO_PIXEL_FORMAT_0RGB1555;
@@ -274,6 +330,8 @@ void retro_init (void)
274330
NDS_CreateDummyFirmware(&fw_config);
275331
NDS_3D_ChangeCore(0);
276332
backup_setManualBackupType(MC_TYPE_AUTODETECT);
333+
334+
msgbox = &msgBoxWnd;
277335
}
278336

279337
void retro_deinit(void)

src/common.cpp

+40-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@
1616
*/
1717

1818
//TODO - move this into ndssystem where it belongs probably
19-
19+
#include <stdarg.h>
2020
#include <string.h>
21-
22-
#ifdef __LIBRETRO__ // Need ctype.h
2321
#include <ctype.h>
24-
#endif
2522

2623
#include <string>
2724
#include "common.h"
@@ -57,3 +54,42 @@ char *removeSpecialChars(char *s)
5754
*buf = 0;
5855
return s;
5956
}
57+
58+
// ===============================================================================
59+
// Message dialogs
60+
// ===============================================================================
61+
#define MSG_PRINT { \
62+
va_list args; \
63+
va_start (args, fmt); \
64+
vprintf (fmt, args); \
65+
va_end (args); \
66+
}
67+
void msgFakeInfo(const char *fmt, ...)
68+
{
69+
MSG_PRINT;
70+
}
71+
72+
bool msgFakeConfirm(const char *fmt, ...)
73+
{
74+
MSG_PRINT;
75+
return true;
76+
}
77+
78+
void msgFakeError(const char *fmt, ...)
79+
{
80+
MSG_PRINT;
81+
}
82+
83+
void msgFakeWarn(const char *fmt, ...)
84+
{
85+
MSG_PRINT;
86+
}
87+
88+
msgBoxInterface msgBoxFake = {
89+
msgFakeInfo,
90+
msgFakeConfirm,
91+
msgFakeError,
92+
msgFakeWarn,
93+
};
94+
95+
msgBoxInterface *msgbox = &msgBoxFake;

src/common.h

+14
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,19 @@ char *intToBin(T val)
8282
extern char *trim(char *s, int len=-1);
8383
extern char *removeSpecialChars(char *s);
8484

85+
// ===============================================================================
86+
// Message dialogs
87+
// ===============================================================================
88+
#define CALL_CONVENTION
89+
typedef struct
90+
{
91+
void (CALL_CONVENTION* info) (const char *fmt, ...);
92+
bool (CALL_CONVENTION* confirm)(const char *fmt, ...);
93+
void (CALL_CONVENTION* error) (const char *fmt, ...);
94+
void (CALL_CONVENTION* warn) (const char *fmt, ...);
95+
} msgBoxInterface;
96+
97+
extern msgBoxInterface *msgbox;
98+
8599
#endif
86100

src/mc.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,7 @@ void BackupDevice::reset_command()
460460
{
461461
case 0:
462462
case 1:
463-
printf("Catastrophic error while autodetecting save type.\nIt will need to be specified manually\n");
464-
#ifdef _WINDOWS
465-
MessageBox(0,"Catastrophic Error Code: Camel;\nyour save type has not been autodetected correctly;\nplease report to developers",0,0);
466-
#endif
463+
msgbox->error("Catastrophic error while autodetecting save type.\nIt will need to be specified manually\n");
467464
addr_size = 1; //choose 1 just to keep the busted savefile from growing too big
468465
break;
469466
case 2:

src/saves.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,7 @@ bool savestate_load(EMUFILE* is)
11071107

11081108
if(!x && !SAV_silent_fail_flag)
11091109
{
1110-
printf("Error loading savestate. It failed halfway through;\nSince there is no savestate backup system, your current game session is wrecked");
1111-
#ifdef _WINDOWS
1112-
//HACK! we really need a better way to handle this kind of feedback
1113-
MessageBox(0,"Error loading savestate. It failed halfway through;\nSince there is no savestate backup system, your current game session is wrecked",0,0);
1114-
#endif
1110+
msgbox->error("Error loading savestate. It failed halfway through;\nSince there is no savestate backup system, your current game session is wrecked");
11151111
return false;
11161112
}
11171113

0 commit comments

Comments
 (0)