X-Git-Url: https://git.decadent.org.uk/gitweb/?p=videolink.git;a=blobdiff_plain;f=webdvd.cpp;h=e80996874157ce339063dd7a5fd5ab30b42aaa4f;hp=e3c02e90f271e757283ddf4f667d5ab8e5296193;hb=a80fac0c4fed899cd5f7503cf4080c30f611e341;hpb=cdd14ea76afc16f91e09323362468eaf5d0bcf9e diff --git a/webdvd.cpp b/webdvd.cpp index e3c02e9..e809968 100644 --- a/webdvd.cpp +++ b/webdvd.cpp @@ -142,6 +142,36 @@ namespace return result; } + + std::string xml_escape(const std::string & str) + { + std::string result; + std::size_t begin = 0; + + for (;;) + { + std::size_t end = str.find_first_of("\"&'<>", begin); + result.append(str, begin, end - begin); + if (end == std::string::npos) + return result; + + const char * entity = NULL; + switch (str[end]) + { + case '"': entity = """; break; + case '&': entity = "&"; break; + case '\'': entity = "'"; break; + case '<': entity = "<"; break; + case '>': entity = ">"; break; + } + assert(entity); + result.append(entity); + + begin = end + 1; + } + } + + struct dvd_contents { enum pgc_type { menu_pgc, title_pgc }; @@ -172,6 +202,9 @@ namespace std::vector
\n" - // Has the location been set yet? + // Initialise the current location if it is not set + // (all general registers are initially 0). " if (g1 eq 0)\n" - " {\n" - // Initialise the current location to first button on - // this menu. - " g1 = " << location_bias << ";\n" - " }\n" - " else\n" - " {\n" - // Has the user selected a link? - " if (g0 ne 0)\n" - " {\n" - // First update the history. - // Does link go to the last page in the history? - " if (((g0 ^ g2) & " << menu_mask - << ") == 0)\n" - // It does; we treat this as going back and pop the old - // location off the history stack into the current - // location. Clear the free stack slot. - " {\n" - " g1 = g2; g2 = g3; g3 = g4; g4 = g5;\n" - " g5 = g6; g6 = g7; g7 = g8; g8 = g9;\n" - " g9 = g10; g10 = g11; g11 = 0;\n" - " }\n" - " else\n" - // Link goes to some other page, so push current - // location onto the history stack and set the current - // location to be exactly the target location. - " {\n" - " g11 = g10; g10 = g9; g9 = g8; g8 = g7;\n" - " g7 = g6; g6 = g5; g5 = g4; g4 = g3;\n" - " g3 = g2; g2 = g1; g1 = g0;\n" - " }\n" - " }\n" - // Find the target page number. - " g0 = g1 & " << menu_mask << ";\n"; - // There seems to be no way to perform a computed jump, - // so we generate all possible jumps and a binary search - // to select the correct one. - generate_menu_dispatch(file, 12, - 0, contents_.menus.size() - 1); - file << - " }\n"; + " g1 = " << 1 + button_mult << ";\n"; } - else // menu_num != 0 + else { file << "\n" " \n"; } + // When a title finishes or the user presses the menu + // button, this always jumps to the titleset's root menu. + // We want to return the user to the last menu they used. + // So we arrange for each titleset's root menu to return + // to the vmgm title menu and then dispatch from there to + // whatever the correct menu is. We determine the correct + // menu by looking at the menu part of g1. + + file << " g0 = g1 & " << menu_mask << ";\n"; + + // There is a limit of 128 VM instructions in each PGC. + // Therefore in each menu'ssection we generate + // jumps to menus with numbers greater by 512, 256, 128, + // ..., 1 where (a) such a menu exists, (b) this menu + // number is divisible by twice that increment and (c) the + // correct menu is that or a later menu. Thus each menu + // has at most 10 such conditional jumps and is reachable + // by at most 10 jumps from the title menu. This chain of + // jumps might take too long on some players; this has yet + // to be investigated. + + for (std::size_t menu_incr = (menu_mask + 1) / 2; + menu_incr != 0; + menu_incr /= 2) + { + if (menu_num + menu_incr < contents.menus.size() + && (menu_num & (menu_incr * 2 - 1)) == 0) + { + file << + " if (g0 ge " << 1 + menu_num + menu_incr + << ")\n" + " jump menu " << 1 + menu_num + menu_incr + << ";\n"; + } + } + file << - // Clear link indicator and highlight the - // appropriate link/button. - " g0 = 0; s8 = g1 & " << button_mask << ";\n" + // Highlight the appropriate button. + " s8 = g1 & " << button_mask << ";\n" "\n" - "\n"; + " \n"; for (std::size_t button_num = 0; button_num != menu.entries.size(); ++button_num) { - file << "
g12 = g1;\n" - << contents_.titles[title_num].vob_list << - // If page/menu location has not been changed during the - // video, change the location to be the following - // link/button when returning to it. In any case, - // return to a page/menu. + << contents.titles[title_num].vob_list << + // If the menu location has not been changed during + // the title, set the location to be the following + // button in the menu. In any case, return to some + // menu. "