- }
-
- void generate_page_dispatch(std::ostream &, int indent,
- int first_page, int last_page);
-
- void WebDvdWindow::generate_dvdauthor_file()
- {
- std::ofstream file("webdvd.dvdauthor");
-
- // We generate code that uses registers in the following way:
- //
- // g0: link destination (when jumping to menu 1), then scratch
- // g1: current location
- // g2-g11: location history (g2 = most recent)
- // g12: location that last linked to a video
- //
- // All locations are divided into two bitfields: the least
- // significant 10 bits are a page/menu number and the most
- // significant 6 bits are a link/button number. This is
- // chosen for compatibility with the encoding of the s8
- // (button) register.
- //
- static const int link_mult = dvd::reg_s8_button_mult;
- static const int page_mask = link_mult - 1;
- static const int link_mask = (1 << dvd::reg_bits) - link_mult;
-
- file <<
- "<dvdauthor>\n"
- " <vmgm>\n"
- " <menus>\n";
-
- for (std::size_t page_num = 1;
- page_num <= page_links_.size();
- ++page_num)
- {
- std::vector<std::string> & page_links =
- page_links_[page_num - 1];
-
- if (page_num == 1)
- {
- // This is the first page (root menu) which needs to
- // include initialisation and dispatch code.
-
- file <<
- " <pgc entry='title'>\n"
- " <pre>\n"
- // Has the location been set yet?
- " if (g1 eq 0)\n"
- " {\n"
- // Initialise the current location to first link on
- // this page.
- " g1 = " << 1 * link_mult + 1 << ";\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) & " << page_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 & " << page_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_page_dispatch(file, 12, 1, page_links_.size());
- file <<
- " }\n";
- }
- else // page_num != 1
- {
- file <<
- " <pgc>\n"
- " <pre>\n";
- }