DVD Studio Pro 2.0 Abstraction Layer

The DVD Studio Pro 2.0 Abstraction layer uses a highly structured template approach. Many of the command sequences are identical in every project, or only differ in the values tested for at the end of the sequence.

Registers

The abstraction layer uses eight general registers (GPRMs) to keep track of things, registers 0 thru 7. It uses the other 8 GPRMs , registers 8 thru 15, for user scripts. The user scripts in DVDSP 2 refer to these registers as GPRM 0 thru GPRM 7, but they are actually r8 thru r15 in the DVD Spec commands.

R0 and r1 are used as scratch registers, which means that command sequences use them to decode what is in other registers so that the other registers are not destroyed. Register 1 is also sometimes used as a parameter passed from one PGC to another. Neither of these registers is ever relied upon between video plays. This means that TFDVDEdit 2 authors are free to use these registers as scratch or parameter registers also.

R2 is used as a parameter. Much of the code that tests r2 is never reached by the projects that I have checked. This would imply that DVDAfterEdit authors could use r2 to retain values between video plays, as long as their code is the first code executed after the play, and they clear it before going to abstraction layer code.

R3 is usually the Title Number.
R4 is probably the Sub picture stream number.
R5 is usually the Chapter Number.

R6 is the GetLastItem register. The abstraction layer code sets r6 to a unique value before playing video. Its use will be covered as we encounter it in the command sequences.

R7 is often set to be the same as r6. No code that tests r7 has been found yet.

All of the conclusions above and below are subject to change as we learn more about the abstraction layer.

First Play PGC

The first play PGC jumps to the asset that the user selected in DVDSP 2, after setting some register values that the abstraction layer will test.

Manager Menus

Every DVDSP 2 project has exactly eight Manager Menus, which are always used in the same way. Often a menu will be blank (contain no commands) if the feature supported by that menu is not used. So far there are no examples of code in PGCs 3, 5, or 7, though there are links to those PGCs that are never executed, since the register tested never contains the appropriate value to cause the link.

VMG PGC 1

This PGC is often similar to the first play PGC.

VMG PGC 2

This PGC is always the same in every project, except for the number of Titles in the project. A project with 6 Titles would read thus:

#Selected from PlayAllProject:Manager Menus:English (8 menus):VMG PGC 2:
1: Set r1 = 0
2: Set r2 = 0
3: if r3 & $ff00 then GoTo Line 5
4: GoTo Line 8
5: Set r5 = r3
6: Set r5 /= $100
7: Set r3 &= $ff
8: if r3 >= 6 then Link PGC 3
9: Set r0 = 1
10: if r0 == r3 then Jump TT 1
11: Set r0 = 2
12: if r0 == r3 then Jump TT 2
13: Set r0 = 3
14: if r0 == r3 then Jump TT 3
15: Set r0 = 4
16: if r0 == r3 then Jump TT 4
17: Set r0 = 5
18: if r0 == r3 then Jump TT 5
19: Jump First Play

We will examine this PGC in detail:

1: Set r1 = 0
2: Set r2 = 0

These instructions clear parameters that might be checked later.

3: if r3 & $ff00 then GoTo Line 5
4: GoTo Line 8

Line 3 tests to see if there is anything in the high-order byte of r3. If there is, it does further decoding at line 5. If there is not, it assumes that r5 and r3 are already fully prepared by the code that came here, and goes to the code which follows the decoding.

5: Set r5 = r3
6: Set r5 /= $100

This moves the high byte of r3 to r5, putting it in the low byte.

7: Set r3 &= $ff

This isolates the Title Number to be a value between 0 and 255.

8: if r3 >= 6 then Link PGC 3

This says if the title number is too large, go to PGC 3, which is empty. Presumably PGC3 could contain error recovery code, or could do something useful with values greater than 99 but less than 256, since the DVD Spec allows only 99 titles.

9: Set r0 = 1
10: if r0 == r3 then Jump TT 1
11: Set r0 = 2
12: if r0 == r3 then Jump TT 2
13: Set r0 = 3
14: if r0 == r3 then Jump TT 3
15: Set r0 = 4
16: if r0 == r3 then Jump TT 4
17: Set r0 = 5
18: if r0 == r3 then Jump TT 5

Each pair of commands checks for a particular Title Number in r3 and jumps to that Title if the number matches.

19: Jump First Play

One possible value of r3 is unaccounted for zero. In that case the DVD starts over at the First Play.

VMG PGC 4

This PGC jumps to a particular VTSM PGC depending on the value of r1. Sometimes there is only one interesting PGC, so r1 is not tested in that case. Often this PGC is called by the Post Commands of a Title. It can also be linked to from VMG PGC 8. Here is an example:

#Selected from PlayAllProject:Manager Menus:English (8 menus):VMG PGC 4:
1: Set r5 = 0
2: Set r2 = 0
3: if r1 >= 4 then GoTo Line 5
4: Jump VTS 1 VTS TT 1 Menu Root
5: Jump VTS 5 VTS TT 1 Menu Root
6: Jump First Play

Obviously the Jump First Play can never be reached. There is likely a more complex situation that could result it being used.

VMG PGC 6

This PGC is very similar to PGC 4, but uses r2 to determine the branch. Here is an example:

#Selected from PlayAllProject:Manager Menus:English (8 menus):VMG PGC 6:
1: Set r5 = 0
2: Set r1 = 0
3: if r2 >= $c then GoTo Line 5
4: Jump VTS 1 VTS TT 1 Menu Root
5: Jump VTS 5 VTS TT 1 Menu Root
6: Jump First Play

VMG PGC 8

This is the longest script in the abstraction layer, but we have not found a link to it yet in the simple projects we have examined. I deleted it from a project and verified to make sure that it wasnt referenced.

It is identical in all projects except for some of the values tested. It is particularly interesting for its splitting up of r2 into subfields, so we will examine it in detail.

#Selected from PlayAllProject:Manager Menus:English (8 menus):VMG PGC 8:
1: Set r0 = r2
2: Set r2 = 0

This moves the value of r2 to r0 in order to test it, and clears r2. The clearing of r2 is probably so that the same parameter would not be processed again if we came back here.

3: if r0 != $fff0 then GoTo Line 5
4: Link Resume

This tests for a single value in order to do a resume.

5: Set r3 = r0
6: Set r3 &= $f800
7: if r3 != $f800 then GoTo Line 15

This uses r3 as a scratch register to test r0, which originally came from r2. Then the lower 11 bits of r3 are masked off, so that we can test the higher 5 bits. If they are not all on, we skip over a fairly long section of code.

8: Set r3 = 0
9: Set r2 = r0
10: Set r2 &= $7ff
11: if r2 >= $c then Link PGC 7
12: Link PGC 6
13: Nop
14: Nop

We take the 11 bits that were masked off and isolate them into r2. Then if the value in them is greater than 12, we link to PGC 7. Otherwise we link to PGC 6. (Ignore the Nops). Since we havent seen an example of PGC 7 yet, we are missing a lot of the details.

15: Set r3 = r0
16: Set r3 &= $c000
17: if r3 != $c000 then GoTo Line 30

We now test to see if the high order 2 bits are on. Notice that we tested for the high order 5 bits earlier, which would have taken precedence.

18: Set r3 = 0
19: Set r3 = r0
20: Set r3 &= $3f80
21: Set r3 /= $80
22: Set r5 = r0
23: Set r5 &= $7f
24: Set r5 += 1
25: Link PGC 2
26: Nop
27: Nop
28: Nop
29: Nop

We isolate 7 bits in the middle, and move them to the lower part of r3. That must be a Title Number, since it takes 7 bits to show a value from 1 to 99. (We also noticed a Title Number in r3 in another PGC, earlier).

We then isolate the Chapter Number and put it in r5, and link to PGC 2. Notice that the value in the register was actually the chapter number minus one, since it added one to it.

If we look back at PGC 2, we will see that it uses the value in r3 to decide which Title to jump to. If we look ahead to the Title Set PGCs, we will see they use r5 to decide which Chapter to jump to.

30: Set r3 = 0
31: Set r1 = r0
32: Set r1 &= $ffe0
33: Set r1 /= $20
34: Set r4 = r0
35: Set r4 &= $1f
36: Set r4 += 1
37: if r1 >= 4 then Link PGC 5
38: Link PGC 4

The remaining case is when the two high order bits are not both on. The value is split into the high-order 11 bits in r1 and the lower 5 bits in r4. R4 is probably the sub picture stream number. Then depending on the value in r1, it links to either PGC 5 or PGC 4.

This concludes the Video Manager PGCs for now. Next will be an analysis of the Video Title Set Menu PGCs.