Implement system.MsgBoxOkCancel

This commit is contained in:
Nunuhara Cabbage
2020-03-06 22:43:42 -08:00
parent 529c7024c2
commit ad7501f962
2 changed files with 30 additions and 2 deletions
+2 -2
View File
@@ -54,7 +54,7 @@ const struct syscall syscalls[NR_SYSCALLS] = {
SYS ( SYS_ERROR, Error ),
SYS ( SYS_EXISTS_SAVE_FILE, ExistsSaveFile ),
SYS ( SYS_IS_DEBUG_MODE, IsDebugMode ),
TODO ( SYS_MSGBOX_OK_CANCEL, MsgBoxOkCancel ),
SYS ( SYS_MSGBOX_OK_CANCEL, MsgBoxOkCancel ),
SYS ( SYS_GET_FUNC_STACK_NAME, GetFuncStackName ),
SYS ( SYS_PEEK, Peek ),
SYS ( SYS_SLEEP, Sleep ),
@@ -243,7 +243,7 @@ struct instruction instructions[NR_OPCODES] = {
TODO ( R_NOTE, 0 ),
OP ( SH_LOCALCREATE, 2, T_LOCAL, T_STRUCT ),
OP ( SH_LOCALDELETE, 1, T_LOCAL ),
TODO ( STOI, 0 ),
OP ( STOI, 0 ),
OP ( A_PUSHBACK, 0 ),
OP ( A_POPBACK, 0 ),
OP ( S_EMPTY, 0 ),
+28
View File
@@ -328,6 +328,11 @@ static void function_return(void)
call_stack_ptr--;
}
static const SDL_MessageBoxButtonData buttons[] = {
{ SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "OK" },
{ SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 0, "Cancel" },
};
static void system_call(enum syscall_code code)
{
switch (code) {
@@ -372,6 +377,29 @@ static void system_call(enum syscall_code code)
// XXX: caller S_POPs
break;
}
case SYS_MSGBOX_OK_CANCEL: {
int result = 0;
struct string *str = stack_peek_string(0);
char *utf = sjis2utf(str->text, str->size);
const SDL_MessageBoxData mbox = {
SDL_MESSAGEBOX_INFORMATION,
NULL,
"xsystem4",
str->text,
SDL_arraysize(buttons),
buttons,
NULL
};
if (SDL_ShowMessageBox(&mbox, &result)) {
WARNING("Error displaying message box");
}
// ...
free(utf);
heap_unref(stack_pop().i);
stack_push(result);
break;
}
case SYS_RESUME_SAVE: {
union vm_value *success = stack_pop_var();
struct string *filename = stack_peek_string(0);