static uint16_t _find_selected_button_id(GRAPHICS_CONTROLLER *gc) { /* executed when playback condition changes (ex. new page, popup-on, ...) */ PG_DISPLAY_SET *s = gc->igs; BD_IG_PAGE *page = NULL; unsigned page_id = bd_psr_read(gc->regs, PSR_MENU_PAGE_ID); unsigned button_id = bd_psr_read(gc->regs, PSR_SELECTED_BUTTON_ID); unsigned ii; page = _find_page(&s->ics->interactive_composition, page_id); if (!page) { GC_TRACE("_find_selected_button_id(): unknown page #%d (have %d pages)\n", page_id, s->ics->interactive_composition.num_pages); return 0xffff; } /* run 5.9.8.3 */ /* 1) always use page->default_selected_button_id_ref if it is valid */ if (_find_button_page(page, page->default_selected_button_id_ref, NULL) && _is_button_enabled(gc, page, page->default_selected_button_id_ref)) { GC_TRACE("_find_selected_button_id() -> default #%d\n", page->default_selected_button_id_ref); return page->default_selected_button_id_ref; } /* 2) fallback to current PSR10 value if it is valid */ for (ii = 0; ii < page->num_bogs; ii++) { BD_IG_BOG *bog = &page->bog[ii]; uint16_t enabled_button = gc->bog_data[ii].enabled_button; if (button_id == enabled_button) { if (_find_button_bog(bog, enabled_button)) { GC_TRACE("_find_selected_button_id() -> PSR10 #%d\n", enabled_button); return enabled_button; } } } /* 3) fallback to find first valid_button_id_ref from page */ for (ii = 0; ii < page->num_bogs; ii++) { BD_IG_BOG *bog = &page->bog[ii]; uint16_t enabled_button = gc->bog_data[ii].enabled_button; if (_find_button_bog(bog, enabled_button)) { GC_TRACE("_find_selected_button_id() -> first valid #%d\n", enabled_button); return enabled_button; } } GC_TRACE("_find_selected_button_id(): not found -> 0xffff\n"); return 0xffff; }
static void _update_selected_button(GRAPHICS_CONTROLLER *gc) { unsigned button_id = bd_psr_read(gc->regs, PSR_SELECTED_BUTTON_ID); TRACE("_update_enabled_button(): currently enabled button is #%d\n", button_id); // special case: triggered only after enable button disables selected button if (button_id & 0x10000) { button_id &= 0xffff; bd_psr_write(gc->regs, PSR_SELECTED_BUTTON_ID, button_id); TRACE("_update_enabled_button() -> #%d [last enabled]\n", button_id); return; } if (button_id == 0xffff) { PG_DISPLAY_SET *s = gc->igs; BD_IG_PAGE *page = NULL; unsigned page_id = bd_psr_read(gc->regs, PSR_MENU_PAGE_ID); page = _find_page(&s->ics->interactive_composition, page_id); if (!page) { TRACE("_update_enabled_button(): unknown page #%d (have %d pages)\n", page_id, s->ics->interactive_composition.num_pages); return; } // run 5.9.8.3 if (_find_button_page(page, page->default_selected_button_id_ref, NULL) && _is_button_enabled(gc, page, page->default_selected_button_id_ref)) { button_id = page->default_selected_button_id_ref; } else { unsigned ii; for (ii = 0; ii < page->num_bogs; ii++) { BD_IG_BOG *bog = &page->bog[ii]; if (_find_button_bog(bog, gc->enabled_button[ii])) { button_id = gc->enabled_button[ii]; break; } } } bd_psr_write(gc->regs, PSR_SELECTED_BUTTON_ID, button_id); TRACE("_update_enabled_button() -> #%d\n", button_id); } }