MGL: support up to 6 actions. New action: reset.

This commit is contained in:
Sorgelig
2022-03-03 23:00:23 +08:00
parent a9b4bb30d8
commit 2e34dcae35
5 changed files with 147 additions and 52 deletions

View File

@@ -1023,13 +1023,44 @@ void HandleUI(void)
mgl_struct *mgl = mgl_get();
if (!mgl->done)
{
if (mgl->timer && CheckTimer(mgl->timer))
switch (mgl->state)
{
mgl->active = 1;
mgl->done = 1;
case 0:
if (CheckTimer(mgl->timer))
{
//printf("*** MGL state=%d,%d\n", mgl->current, mgl->state);
mgl->state = (mgl->item[mgl->current].action == MGL_ACTION_LOAD) ? 1 : 3;
}
break;
case 2:
//printf("*** MGL state=%d,%d\n", mgl->current, mgl->state);
mgl->state = 0;
mgl->current++;
if (mgl->current < mgl->count) mgl->timer = GetTimer(mgl->item[mgl->current].delay * 1000);
else mgl->done = 1;
break;
case 3:
//printf("*** MGL state=%d,%d\n", mgl->current, mgl->state);
user_io_set_kbd_reset(1);
user_io_send_buttons(1);
mgl->timer = GetTimer(mgl->item[mgl->current].hold ? (mgl->item[mgl->current].hold * 1000) : 100);
mgl->state = 4;
break;
case 4:
if (CheckTimer(mgl->timer))
{
//printf("*** MGL state=%d,%d\n", mgl->current, mgl->state);
user_io_set_kbd_reset(0);
user_io_send_buttons(1);
mgl->state = 2;
}
break;
}
}
else if(!mgl->active)
else
{
// get user control codes
c = menu_key_get();
@@ -1309,8 +1340,9 @@ void HandleUI(void)
case MENU_INFO:
if (CheckTimer(menu_timer)) menustate = MENU_NONE1;
// fall through
case MENU_NONE2:
if (menu || (is_menu() && !video_fb_state()) || mgl->active)
if (menu || (is_menu() && !video_fb_state()) || (menustate == MENU_NONE2 && mgl->state == 1))
{
OsdSetSize(16);
if(!is_menu() && (get_key_mod() & (LALT | RALT))) //Alt+Menu
@@ -1348,7 +1380,7 @@ void HandleUI(void)
}
menusub = 0;
OsdClear();
if (mgl->active) OsdDisable();
if (!mgl->done) OsdDisable();
else OsdEnable(DISABLE_KEYBOARD);
}
break;
@@ -1686,7 +1718,7 @@ void HandleUI(void)
if (p[idx] == 'C') idx++;
int num = (p[idx] >= '0' && p[idx] <= '9') ? p[idx] - '0' : 0;
if (mgl->active && num == mgl->index && (p[0] == mgl->type)) mgl->submenu = selentry;
if (!mgl->done && num == mgl->item[mgl->current].index && (p[0] == mgl->item[mgl->current].type)) mgl->item[mgl->current].submenu = selentry;
if (is_x86() && x86_get_image_name(num))
{
@@ -1888,7 +1920,11 @@ void HandleUI(void)
saved_menustate = MENU_GENERIC_MAIN1;
// F/S option not found -> deactivate mgl.
if (mgl->active && mgl->submenu < 0) mgl->active = 0;
if (!mgl->done && mgl->item[mgl->current].submenu < 0)
{
menustate = MENU_NONE1;
mgl->state = 2;
}
if (menu_save_timer && !CheckTimer(menu_save_timer))
{
@@ -1916,11 +1952,11 @@ void HandleUI(void)
page = 0;
}
}
else if (select || recent || minus || plus || mgl->active)
else if (select || recent || minus || plus || !mgl->done)
{
if (mgl->active)
if (!mgl->done)
{
menusub = mgl->submenu;
menusub = mgl->item[mgl->current].submenu;
select = 1;
}
@@ -2033,7 +2069,7 @@ void HandleUI(void)
}
}
if (mgl->active) menustate = MENU_GENERIC_FILE_SELECTED;
if (!mgl->done) menustate = MENU_GENERIC_FILE_SELECTED;
else if (select) SelectFile(Selected_F[ioctl_index & 15], ext, fs_Options, fs_MenuSelect, fs_MenuCancel);
else if (recent_init(ioctl_index)) menustate = MENU_RECENT1;
}
@@ -2083,7 +2119,7 @@ void HandleUI(void)
if (is_psx()) fs_Options |= SCANO_NOZIP;
if (mgl->active) menustate = MENU_GENERIC_IMAGE_SELECTED;
if (!mgl->done) menustate = MENU_GENERIC_IMAGE_SELECTED;
else if (select) SelectFile(Selected_tmp, ext, fs_Options, fs_MenuSelect, fs_MenuCancel);
else if (recent_init(ioctl_index + 500)) menustate = MENU_RECENT1;
}
@@ -2215,14 +2251,13 @@ void HandleUI(void)
case MENU_GENERIC_FILE_SELECTED:
{
if (mgl->active) snprintf(selPath, sizeof(selPath), "%s/%s", HomeDir(), mgl->path);
if (!mgl->done) snprintf(selPath, sizeof(selPath), "%s/%s", HomeDir(), mgl->item[mgl->current].path);
MenuHide();
printf("File selected: %s\n", selPath);
memcpy(Selected_F[ioctl_index & 15], selPath, sizeof(Selected_F[ioctl_index & 15]));
if (!mgl->active && selPath[0]) recent_update(SelectedDir, Selected_F[ioctl_index & 15], SelectedLabel, ioctl_index);
mgl->active = 0;
if (mgl->done && selPath[0]) recent_update(SelectedDir, Selected_F[ioctl_index & 15], SelectedLabel, ioctl_index);
if (store_name)
{
@@ -2255,12 +2290,14 @@ void HandleUI(void)
if (addon[0] == 'f' && addon[1] == '1') process_addon(addon, idx);
}
mgl->state = 2;
}
break;
case MENU_GENERIC_IMAGE_SELECTED:
{
if (mgl->active) snprintf(selPath, sizeof(selPath), "%s/%s", HomeDir(), mgl->path);
if (!mgl->done) snprintf(selPath, sizeof(selPath), "%s/%s", HomeDir(), mgl->item[mgl->current].path);
if (store_name)
{
@@ -2274,8 +2311,7 @@ void HandleUI(void)
printf("Image selected: %s\n", selPath);
memcpy(Selected_S[(int)ioctl_index], selPath, sizeof(Selected_S[(int)ioctl_index]));
if (!mgl->active) recent_update(SelectedDir, Selected_S[(int)ioctl_index], SelectedLabel, ioctl_index + 500);
mgl->active = 0;
if (mgl->done) recent_update(SelectedDir, Selected_S[(int)ioctl_index], SelectedLabel, ioctl_index + 500);
char idx = user_io_ext_idx(selPath, fs_pFileExt) << 6 | ioctl_index;
if (addon[0] == 'f' && addon[1] != '1') process_addon(addon, idx);
@@ -2305,6 +2341,8 @@ void HandleUI(void)
}
if (addon[0] == 'f' && addon[1] == '1') process_addon(addon, idx);
mgl->state = 2;
}
break;

View File

@@ -1227,39 +1227,76 @@ static int scan_mgl(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, const in
case XML_EVENT_START_NODE:
if (!strcasecmp(node->tag, "mistergamedescription")) inside_mgl = 1;
else if (inside_mgl && !strcasecmp(node->tag, "file"))
else if (inside_mgl && mgl.count < (int)(sizeof(mgl.item) / sizeof(mgl.item[0])))
{
for (int i = 0; i < node->n_attributes; i++)
if (!strcasecmp(node->tag, "file"))
{
if (!strcasecmp(node->attributes[i].name, "delay"))
mgl.item[mgl.count].action = MGL_ACTION_LOAD;
for (int i = 0; i < node->n_attributes; i++)
{
mgl.delay = strtoul(node->attributes[i].value, NULL, 0);
mgl.valid |= 0x1;
}
else if (!strcasecmp(node->attributes[i].name, "type"))
{
if (!strcasecmp(node->attributes[i].value, "s"))
if (!strcasecmp(node->attributes[i].name, "delay"))
{
mgl.type = 'S';
mgl.valid |= 0x2;
mgl.item[mgl.count].delay = strtoul(node->attributes[i].value, NULL, 0);
mgl.item[mgl.count].valid |= 0x1;
}
else if (!strcasecmp(node->attributes[i].value, "f"))
else if (!strcasecmp(node->attributes[i].name, "type"))
{
mgl.type = 'F';
mgl.valid |= 0x2;
if (!strcasecmp(node->attributes[i].value, "s"))
{
mgl.item[mgl.count].type = 'S';
mgl.item[mgl.count].valid |= 0x2;
}
else if (!strcasecmp(node->attributes[i].value, "f"))
{
mgl.item[mgl.count].type = 'F';
mgl.item[mgl.count].valid |= 0x2;
}
}
else if (!strcasecmp(node->attributes[i].name, "index"))
{
mgl.item[mgl.count].index = strtoul(node->attributes[i].value, NULL, 0);
mgl.item[mgl.count].valid |= 0x4;
}
else if (!strcasecmp(node->attributes[i].name, "path"))
{
snprintf(mgl.item[mgl.count].path, sizeof(mgl.item[mgl.count].path), "%s", node->attributes[i].value);
mgl.item[mgl.count].valid |= 0x8;
}
}
else if (!strcasecmp(node->attributes[i].name, "index"))
printf(" action=load\n delay=%d\n type=%c\n index=%d\n path=%s\n valid=%X\n\n", mgl.item[mgl.count].delay, mgl.item[mgl.count].type, mgl.item[mgl.count].index, mgl.item[mgl.count].path, mgl.item[mgl.count].valid);
if (mgl.item[mgl.count].valid == 0xF)
{
mgl.index = strtoul(node->attributes[i].value, NULL, 0);
mgl.valid |= 0x4;
mgl.item[mgl.count].valid = 1;
mgl.count++;
}
else if (!strcasecmp(node->attributes[i].name, "path"))
else
{
snprintf(mgl.path, sizeof(mgl.path), "%s", node->attributes[i].value);
mgl.valid |= 0x8;
mgl.item[mgl.count].valid = 0;
}
}
else if (!strcasecmp(node->tag, "reset"))
{
mgl.item[mgl.count].action = MGL_ACTION_RESET;
for (int i = 0; i < node->n_attributes; i++)
{
if (!strcasecmp(node->attributes[i].name, "delay"))
{
mgl.item[mgl.count].delay = strtoul(node->attributes[i].value, NULL, 0);
mgl.item[mgl.count].valid = 1;
}
else if (!strcasecmp(node->attributes[i].name, "hold"))
{
mgl.item[mgl.count].hold = strtoul(node->attributes[i].value, NULL, 0);
}
}
printf(" action=reset\n delay=%d\n hold=%d\n\n", mgl.item[mgl.count].delay, mgl.item[mgl.count].hold);
if (mgl.item[mgl.count].valid) mgl.count++;
}
}
break;
@@ -1283,16 +1320,14 @@ static int scan_mgl(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, const in
mgl_struct* mgl_parse(const char *xml)
{
memset(&mgl, 0, sizeof(mgl));
mgl.submenu = -1;
printf("MGL %s\n", xml);
SAX_Callbacks sax;
SAX_Callbacks_init(&sax);
sax.all_event = scan_mgl;
XMLDoc_parse_file_SAX(xml, &sax, 0);
printf("MGL %s\n delay=%d\n type=%c\n index=%d\n path=%s\n valid=%X\n\n", xml, mgl.delay, mgl.type, mgl.index, mgl.path, mgl.valid);
mgl.parsed = 1;
return &mgl;
}

View File

@@ -27,18 +27,32 @@ struct sw_struct
dip_struct dip[64];
};
struct mgl_struct
#define MGL_ACTION_LOAD 0
#define MGL_ACTION_RESET 1
struct mgl_item_struct
{
char path[1024];
int delay;
char type;
int index;
union
{
int index;
int hold;
};
int valid;
int parsed;
int done;
int active;
int submenu;
int action;
};
struct mgl_struct
{
int count;
int current;
mgl_item_struct item[6];
uint32_t timer;
int state;
int done;
};
sw_struct *arcade_sw(int n);

View File

@@ -1353,13 +1353,13 @@ void user_io_init(const char *path, const char *xml)
SetMidiLinkMode(midilink);
SetUARTMode(uartmode);
if (mgl_get()->valid != 0xF || is_menu() || is_minimig() || is_st() || is_archie() || user_io_core_type() == CORE_TYPE_SHARPMZ)
if (!mgl_get()->count || is_menu() || is_minimig() || is_st() || is_archie() || user_io_core_type() == CORE_TYPE_SHARPMZ)
{
mgl_get()->done = 1;
}
else
{
mgl_get()->timer = GetTimer(mgl_get()->delay * 1000);
mgl_get()->timer = GetTimer(mgl_get()->item[0].delay * 1000);
}
}
@@ -2499,6 +2499,8 @@ int get_vga_fb()
}
static char kbd_reset = 0;
static char kbd_reset_ovr = 0;
void user_io_send_buttons(char force)
{
static unsigned short key_map = 0;
@@ -2508,7 +2510,7 @@ void user_io_send_buttons(char force)
if (user_io_menu_button()) map |= BUTTON1;
if (user_io_user_button()) map |= BUTTON2;
if (kbd_reset) map |= BUTTON2;
if (kbd_reset || kbd_reset_ovr) map |= BUTTON2;
if (cfg.vga_scaler) map |= CONF_VGA_SCALER;
if (cfg.vga_sog) map |= CONF_VGA_SOG;
@@ -2553,7 +2555,12 @@ void user_io_send_buttons(char force)
int user_io_get_kbd_reset()
{
return kbd_reset;
return kbd_reset || kbd_reset_ovr;
}
void user_io_set_kbd_reset(int reset)
{
kbd_reset_ovr = reset;
}
void user_io_set_ini(int ini_num)

View File

@@ -195,6 +195,7 @@ void user_io_read_confstr();
char *user_io_get_confstr(int index);
uint32_t user_io_status(uint32_t, uint32_t, int ex = 0);
int user_io_get_kbd_reset();
void user_io_set_kbd_reset(int reset);
uint32_t user_io_get_file_crc();
int user_io_file_mount(const char *name, unsigned char index = 0, char pre = 0, int pre_size = 0);