Mercurial > libdvdnav.hg
annotate vm.c @ 20:6061277509ee src
Take care of ENDIAN words.
author | f1rmb |
---|---|
date | Mon, 22 Apr 2002 01:10:42 +0000 |
parents | 7e8628911b4f |
children | 3c1df0cb3aee |
rev | line source |
---|---|
0 | 1 /* |
2 * Copyright (C) 2000, 2001 Håkan Hjort | |
3 * Copyright (C) 2001 Rich Wareham <richwareham@users.sourceforge.net> | |
4 * | |
5 * This file is part of libdvdnav, a DVD navigation library. It is modified | |
6 * from a file originally part of the Ogle DVD player. | |
7 * | |
8 * libdvdnav is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * libdvdnav is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
21 * | |
22 * $Id$ | |
23 * | |
24 */ | |
25 | |
26 #ifdef HAVE_CONFIG_H | |
27 #include "config.h" | |
28 #endif | |
29 | |
30 #include <stdio.h> | |
31 #include <string.h> | |
32 #include <stdlib.h> | |
33 #include <unistd.h> | |
34 #include <inttypes.h> | |
35 #include <assert.h> | |
36 | |
37 #include <dvdread/ifo_types.h> | |
38 #include <dvdread/ifo_read.h> | |
39 | |
40 #include "decoder.h" | |
41 #include "vmcmd.h" | |
42 #include "vm.h" | |
43 | |
44 /* Local prototypes */ | |
45 | |
6 | 46 static void saveRSMinfo(vm_t *vm,int cellN, int blockN); |
47 static int set_PGN(vm_t *vm); | |
48 static link_t play_PGC(vm_t *vm); | |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
49 static link_t play_PGC_post(vm_t *vm); |
6 | 50 static link_t play_PG(vm_t *vm); |
51 static link_t play_Cell(vm_t *vm); | |
52 static link_t play_Cell_post(vm_t *vm); | |
53 static link_t process_command(vm_t *vm,link_t link_values); | |
0 | 54 |
6 | 55 static void ifoOpenNewVTSI(vm_t *vm,dvd_reader_t *dvd, int vtsN); |
56 static pgcit_t* get_PGCIT(vm_t *vm); | |
57 static int get_video_aspect(vm_t *vm); | |
0 | 58 |
59 /* Can only be called when in VTS_DOMAIN */ | |
6 | 60 static int get_TT(vm_t *vm,int tt); |
61 static int get_VTS_TT(vm_t *vm,int vtsN, int vts_ttn); | |
62 static int get_VTS_PTT(vm_t *vm,int vtsN, int vts_ttn, int part); | |
14 | 63 static int find_TT(vm_t *vm, int vtsN, int vts_ttn); |
0 | 64 |
6 | 65 static int get_MENU(vm_t *vm,int menu); /* VTSM & VMGM */ |
66 static int get_FP_PGC(vm_t *vm); /* FP */ | |
0 | 67 |
68 /* Called in any domain */ | |
6 | 69 static int get_ID(vm_t *vm,int id); |
70 static int get_PGC(vm_t *vm,int pgcN); | |
71 static int get_PGCN(vm_t *vm); | |
0 | 72 |
73 /* Initialisation */ | |
74 | |
75 vm_t* vm_new_vm() { | |
76 vm_t *vm = (vm_t*)calloc(sizeof(vm_t), sizeof(char)); | |
77 | |
78 return vm; | |
79 } | |
80 | |
6 | 81 static void vm_print_current_domain_state(vm_t *vm) { |
82 switch((vm->state).domain) { | |
0 | 83 case VTS_DOMAIN: |
84 fprintf(stderr, "Video Title Domain: -\n"); | |
85 break; | |
86 | |
87 case VTSM_DOMAIN: | |
88 fprintf(stderr, "Video Title Menu Domain: -\n"); | |
89 break; | |
90 | |
91 case VMGM_DOMAIN: | |
92 fprintf(stderr, "Video Manager Menu Domain: -\n"); | |
93 break; | |
94 | |
95 case FP_DOMAIN: | |
96 fprintf(stderr, "First Play Domain: -\n"); | |
97 break; | |
98 | |
99 default: | |
100 fprintf(stderr, "Unknown Domain: -\n"); | |
101 break; | |
102 } | |
103 fprintf(stderr, "VTS:%d PG:%u CELL:%u BLOCK:%u VTS_TTN:%u TTN:%u TT_PGCN:%u\n", | |
6 | 104 (vm->state).vtsN, |
105 (vm->state).pgN, | |
106 (vm->state).cellN, | |
107 (vm->state).blockN, | |
108 (vm->state).VTS_TTN_REG, | |
109 (vm->state).TTN_REG, | |
110 (vm->state).TT_PGCN_REG); | |
0 | 111 } |
112 | |
6 | 113 void vm_stop(vm_t *vm) { |
114 if(!vm) | |
0 | 115 return; |
116 | |
6 | 117 if(vm->vmgi) { |
118 ifoClose(vm->vmgi); | |
119 vm->vmgi=NULL; | |
0 | 120 } |
121 | |
6 | 122 if(vm->vtsi) { |
123 ifoClose(vm->vtsi); | |
124 vm->vmgi=NULL; | |
0 | 125 } |
126 | |
6 | 127 if(vm->dvd) { |
128 DVDClose(vm->dvd); | |
129 vm->dvd=NULL; | |
0 | 130 } |
131 } | |
132 | |
6 | 133 void vm_free_vm(vm_t *vm) { |
134 if(vm) { | |
135 vm_stop(vm); | |
136 free(vm); | |
0 | 137 } |
138 } | |
139 | |
140 /* IFO Access */ | |
141 | |
6 | 142 ifo_handle_t *vm_get_vmgi(vm_t *vm) { |
143 if(!vm) | |
0 | 144 return NULL; |
145 | |
6 | 146 return vm->vmgi; |
0 | 147 } |
148 | |
6 | 149 ifo_handle_t *vm_get_vtsi(vm_t *vm) { |
150 if(!vm) | |
0 | 151 return NULL; |
152 | |
6 | 153 return vm->vtsi; |
0 | 154 } |
155 | |
156 /* Reader Access */ | |
157 | |
6 | 158 dvd_reader_t *vm_get_dvd_reader(vm_t *vm) { |
159 if(!vm) | |
0 | 160 return NULL; |
161 | |
6 | 162 return vm->dvd; |
0 | 163 } |
164 | |
17 | 165 int vm_reset(vm_t *vm, char *dvdroot) /* , register_t regs) */ { |
0 | 166 /* Setup State */ |
6 | 167 memset((vm->state).registers.SPRM, 0, sizeof(uint16_t)*24); |
168 memset((vm->state).registers.GPRM, 0, sizeof((vm->state).registers.GPRM)); | |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
169 memset((vm->state).registers.GPRM_mode, 0, sizeof((vm->state).registers.GPRM_mode)); |
19
7e8628911b4f
Implement General Register Counters or GPRM counters.
jcdutton
parents:
18
diff
changeset
|
170 memset((vm->state).registers.GPRM_mode, 0, sizeof((vm->state).registers.GPRM_mode)); |
7e8628911b4f
Implement General Register Counters or GPRM counters.
jcdutton
parents:
18
diff
changeset
|
171 memset((vm->state).registers.GPRM_time, 0, sizeof((vm->state).registers.GPRM_time)); |
6 | 172 (vm->state).registers.SPRM[0] = ('e'<<8)|'n'; /* Player Menu Languange code */ |
173 (vm->state).AST_REG = 15; /* 15 why? */ | |
174 (vm->state).SPST_REG = 62; /* 62 why? */ | |
175 (vm->state).AGL_REG = 1; | |
176 (vm->state).TTN_REG = 1; | |
177 (vm->state).VTS_TTN_REG = 1; | |
178 /* (vm->state).TT_PGCN_REG = 0 */ | |
179 (vm->state).PTTN_REG = 1; | |
180 (vm->state).HL_BTNN_REG = 1 << 10; | |
0 | 181 |
6 | 182 (vm->state).PTL_REG = 15; /* Parental Level */ |
183 (vm->state).registers.SPRM[12] = ('U'<<8)|'S'; /* Parental Management Country Code */ | |
184 (vm->state).registers.SPRM[16] = ('e'<<8)|'n'; /* Initial Language Code for Audio */ | |
185 (vm->state).registers.SPRM[18] = ('e'<<8)|'n'; /* Initial Language Code for Spu */ | |
0 | 186 /* Player Regional Code Mask. |
187 * bit0 = Region 1 | |
188 * bit1 = Region 2 | |
189 */ | |
6 | 190 (vm->state).registers.SPRM[20] = 0x1; /* Player Regional Code Mask. Region free! */ |
191 (vm->state).registers.SPRM[14] = 0x100; /* Try Pan&Scan */ | |
0 | 192 |
6 | 193 (vm->state).pgN = 0; |
194 (vm->state).cellN = 0; | |
0 | 195 |
6 | 196 (vm->state).domain = FP_DOMAIN; |
197 (vm->state).rsm_vtsN = 0; | |
198 (vm->state).rsm_cellN = 0; | |
199 (vm->state).rsm_blockN = 0; | |
0 | 200 |
6 | 201 (vm->state).vtsN = -1; |
0 | 202 |
6 | 203 if (vm->dvd && dvdroot) { |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
204 // a new dvd device has been requested |
6 | 205 vm_stop(vm); |
0 | 206 } |
6 | 207 if (!vm->dvd) { |
208 vm->dvd = DVDOpen(dvdroot); | |
209 if(!vm->dvd) { | |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
210 fprintf(stderr, "vm: faild to open/read the DVD\n"); |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
211 return -1; |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
212 } |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
213 |
6 | 214 vm->vmgi = ifoOpenVMGI(vm->dvd); |
215 if(!vm->vmgi) { | |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
216 fprintf(stderr, "vm: faild to read VIDEO_TS.IFO\n"); |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
217 return -1; |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
218 } |
6 | 219 if(!ifoRead_FP_PGC(vm->vmgi)) { |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
220 fprintf(stderr, "vm: ifoRead_FP_PGC failed\n"); |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
221 return -1; |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
222 } |
6 | 223 if(!ifoRead_TT_SRPT(vm->vmgi)) { |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
224 fprintf(stderr, "vm: ifoRead_TT_SRPT failed\n"); |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
225 return -1; |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
226 } |
6 | 227 if(!ifoRead_PGCI_UT(vm->vmgi)) { |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
228 fprintf(stderr, "vm: ifoRead_PGCI_UT failed\n"); |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
229 return -1; |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
230 } |
6 | 231 if(!ifoRead_PTL_MAIT(vm->vmgi)) { |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
232 fprintf(stderr, "vm: ifoRead_PTL_MAIT failed\n"); |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
233 ; /* return -1; Not really used for now.. */ |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
234 } |
6 | 235 if(!ifoRead_VTS_ATRT(vm->vmgi)) { |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
236 fprintf(stderr, "vm: ifoRead_VTS_ATRT failed\n"); |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
237 ; /* return -1; Not really used for now.. */ |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
238 } |
6 | 239 if(!ifoRead_VOBU_ADMAP(vm->vmgi)) { |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
240 fprintf(stderr, "vm: ifoRead_VOBU_ADMAP vgmi failed\n"); |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
241 ; /* return -1; Not really used for now.. */ |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
242 } |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
243 /* ifoRead_TXTDT_MGI(vmgi); Not implemented yet */ |
0 | 244 } |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
245 else fprintf(stderr, "vm: reset\n"); |
18 | 246 if (vm->vmgi) { |
247 fprintf(stderr, "DVD disk reports itself with Region mask 0x%08x. Maybe region %u.\n", | |
248 vm->vmgi->vmgi_mat->vmg_category, | |
249 (((vm->vmgi->vmgi_mat->vmg_category >> 16) ^ 0xff) & 0xff) ); | |
250 } | |
0 | 251 return 0; |
252 } | |
253 | |
254 /* FIXME TODO XXX $$$ Handle error condition too... */ | |
6 | 255 int vm_start(vm_t *vm) |
0 | 256 { |
257 link_t link_values; | |
258 | |
9 | 259 /* Set pgc to FP(First Play) pgc */ |
6 | 260 get_FP_PGC(vm); |
261 link_values = play_PGC(vm); | |
262 link_values = process_command(vm,link_values); | |
0 | 263 assert(link_values.command == PlayThis); |
6 | 264 (vm->state).blockN = link_values.data1; |
0 | 265 |
266 return 0; /* ?? */ | |
267 } | |
268 | |
6 | 269 int vm_start_title(vm_t *vm, int tt) { |
0 | 270 link_t link_values; |
271 | |
6 | 272 get_TT(vm, tt); |
273 link_values = play_PGC(vm); | |
274 link_values = process_command(vm, link_values); | |
0 | 275 assert(link_values.command == PlayThis); |
6 | 276 (vm->state).blockN = link_values.data1; |
0 | 277 |
278 return 0; /* ?? */ | |
279 } | |
280 | |
6 | 281 int vm_jump_prog(vm_t *vm, int pr) { |
0 | 282 link_t link_values; |
283 | |
6 | 284 (vm->state).pgN = pr; /* ?? */ |
0 | 285 |
6 | 286 get_PGC(vm, get_PGCN(vm)); |
287 link_values = play_PG(vm); | |
288 link_values = process_command(vm, link_values); | |
0 | 289 assert(link_values.command == PlayThis); |
6 | 290 (vm->state).blockN = link_values.data1; |
0 | 291 |
292 return 0; /* ?? */ | |
293 } | |
294 | |
6 | 295 int vm_eval_cmd(vm_t *vm, vm_cmd_t *cmd) |
0 | 296 { |
297 link_t link_values; | |
298 | |
6 | 299 if(vmEval_CMD(cmd, 1, &(vm->state).registers, &link_values)) { |
300 link_values = process_command(vm, link_values); | |
0 | 301 assert(link_values.command == PlayThis); |
6 | 302 (vm->state).blockN = link_values.data1; |
0 | 303 return 1; /* Something changed, Jump */ |
304 } else { | |
305 return 0; /* It updated some state thats all... */ | |
306 } | |
307 } | |
308 | |
6 | 309 int vm_get_next_cell(vm_t *vm) |
0 | 310 { |
311 link_t link_values; | |
6 | 312 link_values = play_Cell_post(vm); |
313 link_values = process_command(vm,link_values); | |
0 | 314 assert(link_values.command == PlayThis); |
6 | 315 (vm->state).blockN = link_values.data1; |
0 | 316 |
317 return 0; /* ?? */ | |
318 } | |
319 | |
6 | 320 int vm_top_pg(vm_t *vm) |
0 | 321 { |
322 link_t link_values; | |
6 | 323 link_values = play_PG(vm); |
324 link_values = process_command(vm,link_values); | |
0 | 325 assert(link_values.command == PlayThis); |
6 | 326 (vm->state).blockN = link_values.data1; |
0 | 327 |
328 return 1; /* Jump */ | |
329 } | |
330 | |
6 | 331 int vm_go_up(vm_t *vm) |
0 | 332 { |
333 link_t link_values; | |
334 | |
6 | 335 if(get_PGC(vm, (vm->state).pgc->goup_pgc_nr)) |
0 | 336 assert(0); |
337 | |
6 | 338 link_values = play_PGC(vm); |
339 link_values = process_command(vm,link_values); | |
0 | 340 assert(link_values.command == PlayThis); |
6 | 341 (vm->state).blockN = link_values.data1; |
0 | 342 |
343 return 1; /* Jump */ | |
344 } | |
345 | |
6 | 346 int vm_next_pg(vm_t *vm) |
0 | 347 { |
348 /* Do we need to get a updated pgN value first? */ | |
6 | 349 (vm->state).pgN += 1; |
350 return vm_top_pg(vm); | |
0 | 351 } |
352 | |
6 | 353 int vm_prev_pg(vm_t *vm) |
0 | 354 { |
355 /* Do we need to get a updated pgN value first? */ | |
6 | 356 (vm->state).pgN -= 1; |
357 if((vm->state).pgN == 0) { | |
0 | 358 /* Check for previous PGCN ? */ |
6 | 359 (vm->state).pgN = 1; |
0 | 360 /* return 0; */ |
361 } | |
6 | 362 return vm_top_pg(vm); |
0 | 363 } |
364 | |
365 | |
366 static domain_t menuid2domain(DVDMenuID_t menuid) | |
367 { | |
368 domain_t result = VTSM_DOMAIN; /* Really shouldn't have to.. */ | |
369 | |
370 switch(menuid) { | |
371 case DVD_MENU_Title: | |
372 result = VMGM_DOMAIN; | |
373 break; | |
374 case DVD_MENU_Root: | |
375 case DVD_MENU_Subpicture: | |
376 case DVD_MENU_Audio: | |
377 case DVD_MENU_Angle: | |
378 case DVD_MENU_Part: | |
379 result = VTSM_DOMAIN; | |
380 break; | |
381 } | |
382 | |
383 return result; | |
384 } | |
385 | |
6 | 386 int vm_menu_call(vm_t *vm, DVDMenuID_t menuid, int block) |
0 | 387 { |
388 domain_t old_domain; | |
389 link_t link_values; | |
390 | |
391 /* Should check if we are allowed/can acces this menu */ | |
392 | |
393 | |
394 /* FIXME XXX $$$ How much state needs to be restored | |
395 * when we fail to find a menu? */ | |
396 | |
6 | 397 old_domain = (vm->state).domain; |
0 | 398 |
6 | 399 switch((vm->state).domain) { |
0 | 400 case VTS_DOMAIN: |
6 | 401 saveRSMinfo(vm, 0, block); |
0 | 402 /* FALL THROUGH */ |
403 case VTSM_DOMAIN: | |
404 case VMGM_DOMAIN: | |
6 | 405 (vm->state).domain = menuid2domain(menuid); |
406 if(get_PGCIT(vm) != NULL && get_MENU(vm, menuid) != -1) { | |
407 link_values = play_PGC(vm); | |
408 link_values = process_command(vm, link_values); | |
0 | 409 assert(link_values.command == PlayThis); |
6 | 410 (vm->state).blockN = link_values.data1; |
0 | 411 return 1; /* Jump */ |
412 } else { | |
6 | 413 (vm->state).domain = old_domain; |
0 | 414 } |
415 break; | |
416 case FP_DOMAIN: /* FIXME XXX $$$ What should we do here? */ | |
417 break; | |
418 } | |
419 | |
420 return 0; | |
421 } | |
422 | |
423 | |
6 | 424 int vm_resume(vm_t *vm) |
0 | 425 { |
426 int i; | |
427 link_t link_values; | |
428 | |
429 /* Check and see if there is any rsm info!! */ | |
6 | 430 if((vm->state).rsm_vtsN == 0) { |
0 | 431 return 0; |
432 } | |
433 | |
6 | 434 (vm->state).domain = VTS_DOMAIN; |
435 ifoOpenNewVTSI(vm, vm->dvd, (vm->state).rsm_vtsN); | |
436 get_PGC(vm, (vm->state).rsm_pgcN); | |
0 | 437 |
438 /* These should never be set in SystemSpace and/or MenuSpace */ | |
6 | 439 /* (vm->state).TTN_REG = (vm->state).rsm_tt; */ |
440 /* (vm->state).TT_PGCN_REG = (vm->state).rsm_pgcN; */ | |
441 /* (vm->state).HL_BTNN_REG = (vm->state).rsm_btnn; */ | |
0 | 442 for(i = 0; i < 5; i++) { |
6 | 443 (vm->state).registers.SPRM[4 + i] = (vm->state).rsm_regs[i]; |
0 | 444 } |
445 | |
6 | 446 if((vm->state).rsm_cellN == 0) { |
447 assert((vm->state).cellN); /* Checking if this ever happens */ | |
448 (vm->state).pgN = 1; | |
449 link_values = play_PG(vm); | |
450 link_values = process_command(vm, link_values); | |
0 | 451 assert(link_values.command == PlayThis); |
6 | 452 (vm->state).blockN = link_values.data1; |
0 | 453 } else { |
6 | 454 (vm->state).cellN = (vm->state).rsm_cellN; |
455 (vm->state).blockN = (vm->state).rsm_blockN; | |
456 /* (vm->state).pgN = ?? does this gets the righ value in play_Cell, no! */ | |
457 if(set_PGN(vm)) { | |
0 | 458 /* Were at or past the end of the PGC, should not happen for a RSM */ |
459 assert(0); | |
6 | 460 play_PGC_post(vm); |
0 | 461 } |
462 } | |
463 | |
464 return 1; /* Jump */ | |
465 } | |
466 | |
467 /** | |
468 * Return the substream id for 'logical' audio stream audioN. | |
469 * 0 <= audioN < 8 | |
470 */ | |
6 | 471 int vm_get_audio_stream(vm_t *vm, int audioN) |
0 | 472 { |
473 int streamN = -1; | |
3
328eadb3f37e
Added initial example programs directory and make sure all debug/error output goes to stderr.
richwareham
parents:
0
diff
changeset
|
474 fprintf(stderr,"dvdnav:vm.c:get_audio_stream audioN=%d\n",audioN); |
6 | 475 if((vm->state).domain == VTSM_DOMAIN |
476 || (vm->state).domain == VMGM_DOMAIN | |
477 || (vm->state).domain == FP_DOMAIN) { | |
0 | 478 audioN = 0; |
479 } | |
480 | |
481 if(audioN < 8) { | |
482 /* Is there any contol info for this logical stream */ | |
6 | 483 if((vm->state).pgc->audio_control[audioN] & (1<<15)) { |
484 streamN = ((vm->state).pgc->audio_control[audioN] >> 8) & 0x07; | |
0 | 485 } |
486 } | |
487 | |
6 | 488 if((vm->state).domain == VTSM_DOMAIN |
489 || (vm->state).domain == VMGM_DOMAIN | |
490 || (vm->state).domain == FP_DOMAIN) { | |
0 | 491 if(streamN == -1) |
492 streamN = 0; | |
493 } | |
494 | |
495 /* Should also check in vtsi/vmgi status that what kind of stream | |
496 * it is (ac3/lpcm/dts/sdds...) to find the right (sub)stream id */ | |
497 return streamN; | |
498 } | |
499 | |
500 /** | |
501 * Return the substream id for 'logical' subpicture stream subpN. | |
502 * 0 <= subpN < 32 | |
503 */ | |
6 | 504 int vm_get_subp_stream(vm_t *vm, int subpN) |
0 | 505 { |
506 int streamN = -1; | |
6 | 507 int source_aspect = get_video_aspect(vm); |
0 | 508 |
6 | 509 if((vm->state).domain == VTSM_DOMAIN |
510 || (vm->state).domain == VMGM_DOMAIN | |
511 || (vm->state).domain == FP_DOMAIN) { | |
0 | 512 subpN = 0; |
513 } | |
514 | |
515 if(subpN < 32) { /* a valid logical stream */ | |
516 /* Is this logical stream present */ | |
6 | 517 if((vm->state).pgc->subp_control[subpN] & (1<<31)) { |
0 | 518 if(source_aspect == 0) /* 4:3 */ |
6 | 519 streamN = ((vm->state).pgc->subp_control[subpN] >> 24) & 0x1f; |
0 | 520 if(source_aspect == 3) /* 16:9 */ |
6 | 521 streamN = ((vm->state).pgc->subp_control[subpN] >> 16) & 0x1f; |
0 | 522 } |
523 } | |
524 | |
525 /* Paranoia.. if no stream select 0 anyway */ | |
526 /* I am not paranoid */ | |
6 | 527 /* if((vm->state).domain == VTSM_DOMAIN |
528 || (vm->state).domain == VMGM_DOMAIN | |
529 || (vm->state).domain == FP_DOMAIN) { | |
0 | 530 if(streamN == -1) |
531 streamN = 0; | |
532 } | |
533 */ | |
534 /* Should also check in vtsi/vmgi status that what kind of stream it is. */ | |
535 return streamN; | |
536 } | |
537 | |
6 | 538 int vm_get_subp_active_stream(vm_t *vm) |
0 | 539 { |
540 int subpN; | |
541 int streamN; | |
6 | 542 subpN = (vm->state).SPST_REG & ~0x40; |
543 streamN = vm_get_subp_stream(vm, subpN); | |
0 | 544 |
545 /* If no such stream, then select the first one that exists. */ | |
546 if(streamN == -1) { | |
547 for(subpN = 0; subpN < 32; subpN++) { | |
6 | 548 if((vm->state).pgc->subp_control[subpN] & (1<<31)) { |
0 | 549 |
6 | 550 streamN = vm_get_subp_stream(vm, subpN); |
0 | 551 break; |
552 } | |
553 } | |
554 } | |
555 | |
556 /* We should instead send the on/off status to the spudecoder / mixer */ | |
557 /* If we are in the title domain see if the spu mixing is on */ | |
6 | 558 if((vm->state).domain == VTS_DOMAIN && !((vm->state).SPST_REG & 0x40)) { |
0 | 559 /* Bit 7 set means hide, and only let Forced display show */ |
560 return (streamN | 0x80); | |
561 } else { | |
562 return streamN; | |
563 } | |
564 } | |
565 | |
6 | 566 int vm_get_audio_active_stream(vm_t *vm) |
0 | 567 { |
568 int audioN; | |
569 int streamN; | |
6 | 570 audioN = (vm->state).AST_REG ; |
571 streamN = vm_get_audio_stream(vm, audioN); | |
0 | 572 |
573 /* If no such stream, then select the first one that exists. */ | |
574 if(streamN == -1) { | |
575 for(audioN = 0; audioN < 8; audioN++) { | |
6 | 576 if((vm->state).pgc->audio_control[audioN] & (1<<15)) { |
577 streamN = vm_get_audio_stream(vm, audioN); | |
0 | 578 break; |
579 } | |
580 } | |
581 } | |
582 | |
583 return streamN; | |
584 } | |
585 | |
586 | |
6 | 587 void vm_get_angle_info(vm_t *vm, int *num_avail, int *current) |
0 | 588 { |
589 *num_avail = 1; | |
590 *current = 1; | |
591 | |
6 | 592 if((vm->state).domain == VTS_DOMAIN) { |
0 | 593 /* TTN_REG does not allways point to the correct title.. */ |
594 title_info_t *title; | |
6 | 595 if((vm->state).TTN_REG > vm->vmgi->tt_srpt->nr_of_srpts) |
0 | 596 return; |
6 | 597 title = &vm->vmgi->tt_srpt->title[(vm->state).TTN_REG - 1]; |
598 if(title->title_set_nr != (vm->state).vtsN || | |
599 title->vts_ttn != (vm->state).VTS_TTN_REG) | |
0 | 600 return; |
601 *num_avail = title->nr_of_angles; | |
6 | 602 *current = (vm->state).AGL_REG; |
0 | 603 if(*current > *num_avail) /* Is this really a good idea? */ |
604 *current = *num_avail; | |
605 } | |
606 } | |
607 | |
608 | |
6 | 609 void vm_get_audio_info(vm_t *vm, int *num_avail, int *current) |
0 | 610 { |
6 | 611 if((vm->state).domain == VTS_DOMAIN) { |
612 *num_avail = vm->vtsi->vtsi_mat->nr_of_vts_audio_streams; | |
613 *current = (vm->state).AST_REG; | |
614 } else if((vm->state).domain == VTSM_DOMAIN) { | |
615 *num_avail = vm->vtsi->vtsi_mat->nr_of_vtsm_audio_streams; /* 1 */ | |
0 | 616 *current = 1; |
6 | 617 } else if((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN) { |
618 *num_avail = vm->vmgi->vmgi_mat->nr_of_vmgm_audio_streams; /* 1 */ | |
0 | 619 *current = 1; |
620 } | |
621 } | |
622 | |
6 | 623 void vm_get_subp_info(vm_t *vm, int *num_avail, int *current) |
0 | 624 { |
6 | 625 if((vm->state).domain == VTS_DOMAIN) { |
626 *num_avail = vm->vtsi->vtsi_mat->nr_of_vts_subp_streams; | |
627 *current = (vm->state).SPST_REG; | |
628 } else if((vm->state).domain == VTSM_DOMAIN) { | |
629 *num_avail = vm->vtsi->vtsi_mat->nr_of_vtsm_subp_streams; /* 1 */ | |
0 | 630 *current = 0x41; |
6 | 631 } else if((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN) { |
632 *num_avail = vm->vmgi->vmgi_mat->nr_of_vmgm_subp_streams; /* 1 */ | |
0 | 633 *current = 0x41; |
634 } | |
635 } | |
636 | |
6 | 637 subp_attr_t vm_get_subp_attr(vm_t *vm, int streamN) |
0 | 638 { |
639 subp_attr_t attr; | |
640 | |
6 | 641 if((vm->state).domain == VTS_DOMAIN) { |
642 attr = vm->vtsi->vtsi_mat->vts_subp_attr[streamN]; | |
643 } else if((vm->state).domain == VTSM_DOMAIN) { | |
644 attr = vm->vtsi->vtsi_mat->vtsm_subp_attr; | |
645 } else if((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN) { | |
646 attr = vm->vmgi->vmgi_mat->vmgm_subp_attr; | |
0 | 647 } |
648 return attr; | |
649 } | |
650 | |
6 | 651 audio_attr_t vm_get_audio_attr(vm_t *vm, int streamN) |
0 | 652 { |
653 audio_attr_t attr; | |
654 | |
6 | 655 if((vm->state).domain == VTS_DOMAIN) { |
656 attr = vm->vtsi->vtsi_mat->vts_audio_attr[streamN]; | |
657 } else if((vm->state).domain == VTSM_DOMAIN) { | |
658 attr = vm->vtsi->vtsi_mat->vtsm_audio_attr; | |
659 } else if((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN) { | |
660 attr = vm->vmgi->vmgi_mat->vmgm_audio_attr; | |
0 | 661 } |
662 return attr; | |
663 } | |
664 | |
6 | 665 video_attr_t vm_get_video_attr(vm_t *vm) |
0 | 666 { |
667 video_attr_t attr; | |
668 | |
6 | 669 if((vm->state).domain == VTS_DOMAIN) { |
670 attr = vm->vtsi->vtsi_mat->vts_video_attr; | |
671 } else if((vm->state).domain == VTSM_DOMAIN) { | |
672 attr = vm->vtsi->vtsi_mat->vtsm_video_attr; | |
673 } else if((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN) { | |
674 attr = vm->vmgi->vmgi_mat->vmgm_video_attr; | |
0 | 675 } |
676 return attr; | |
677 } | |
678 | |
6 | 679 void vm_get_video_res(vm_t *vm, int *width, int *height) |
0 | 680 { |
681 video_attr_t attr; | |
682 | |
6 | 683 attr = vm_get_video_attr(vm); |
0 | 684 |
685 if(attr.video_format != 0) | |
686 *height = 576; | |
687 else | |
688 *height = 480; | |
689 switch(attr.picture_size) { | |
690 case 0: | |
691 *width = 720; | |
692 break; | |
693 case 1: | |
694 *width = 704; | |
695 break; | |
696 case 2: | |
697 *width = 352; | |
698 break; | |
699 case 3: | |
700 *width = 352; | |
701 *height /= 2; | |
702 break; | |
703 } | |
704 } | |
705 | |
706 /* Must be called before domain is changed (get_PGCN()) */ | |
6 | 707 static void saveRSMinfo(vm_t *vm, int cellN, int blockN) |
0 | 708 { |
709 int i; | |
710 | |
711 if(cellN != 0) { | |
6 | 712 (vm->state).rsm_cellN = cellN; |
713 (vm->state).rsm_blockN = 0; | |
0 | 714 } else { |
6 | 715 (vm->state).rsm_cellN = (vm->state).cellN; |
716 (vm->state).rsm_blockN = blockN; | |
0 | 717 } |
6 | 718 (vm->state).rsm_vtsN = (vm->state).vtsN; |
719 (vm->state).rsm_pgcN = get_PGCN(vm); | |
0 | 720 |
6 | 721 /* assert((vm->state).rsm_pgcN == (vm->state).TT_PGCN_REG); // for VTS_DOMAIN */ |
0 | 722 |
723 for(i = 0; i < 5; i++) { | |
6 | 724 (vm->state).rsm_regs[i] = (vm->state).registers.SPRM[4 + i]; |
0 | 725 } |
726 } | |
727 | |
728 | |
729 | |
6 | 730 /* Figure out the correct pgN from the cell and update (vm->state). */ |
731 static int set_PGN(vm_t *vm) { | |
0 | 732 int new_pgN = 0; |
733 | |
6 | 734 while(new_pgN < (vm->state).pgc->nr_of_programs |
735 && (vm->state).cellN >= (vm->state).pgc->program_map[new_pgN]) | |
0 | 736 new_pgN++; |
737 | |
6 | 738 if(new_pgN == (vm->state).pgc->nr_of_programs) /* We are at the last program */ |
739 if((vm->state).cellN > (vm->state).pgc->nr_of_cells) | |
0 | 740 return 1; /* We are past the last cell */ |
741 | |
6 | 742 (vm->state).pgN = new_pgN; |
0 | 743 |
6 | 744 if((vm->state).domain == VTS_DOMAIN) { |
0 | 745 playback_type_t *pb_ty; |
6 | 746 if((vm->state).TTN_REG > vm->vmgi->tt_srpt->nr_of_srpts) |
0 | 747 return 0; /* ?? */ |
6 | 748 pb_ty = &vm->vmgi->tt_srpt->title[(vm->state).TTN_REG - 1].pb_ty; |
0 | 749 if(pb_ty->multi_or_random_pgc_title == /* One_Sequential_PGC_Title */ 0) { |
750 #if 0 /* TTN_REG can't be trusted to have a correct value here... */ | |
751 vts_ptt_srpt_t *ptt_srpt = vtsi->vts_ptt_srpt; | |
6 | 752 assert((vm->state).VTS_TTN_REG <= ptt_srpt->nr_of_srpts); |
753 assert(get_PGCN() == ptt_srpt->title[(vm->state).VTS_TTN_REG - 1].ptt[0].pgcn); | |
754 assert(1 == ptt_srpt->title[(vm->state).VTS_TTN_REG - 1].ptt[0].pgn); | |
0 | 755 #endif |
6 | 756 (vm->state).PTTN_REG = (vm->state).pgN; |
0 | 757 } |
758 } | |
759 | |
760 return 0; | |
761 } | |
762 | |
6 | 763 static link_t play_PGC(vm_t *vm) |
0 | 764 { |
765 link_t link_values; | |
766 | |
767 fprintf(stderr, "vm: play_PGC:"); | |
6 | 768 if((vm->state).domain != FP_DOMAIN) |
769 fprintf(stderr, " (vm->state).pgcN (%i)\n", get_PGCN(vm)); | |
0 | 770 else |
771 fprintf(stderr, " first_play_pgc\n"); | |
772 | |
773 /* This must be set before the pre-commands are executed because they */ | |
774 /* might contain a CallSS that will save resume state */ | |
6 | 775 (vm->state).pgN = 1; |
776 (vm->state).cellN = 0; | |
0 | 777 |
778 /* eval -> updates the state and returns either | |
779 - some kind of jump (Jump(TT/SS/VTS_TTN/CallSS/link C/PG/PGC/PTTN) | |
780 - just play video i.e first PG | |
781 (This is what happens if you fall of the end of the pre_cmds) | |
782 - or a error (are there more cases?) */ | |
6 | 783 if((vm->state).pgc->command_tbl && (vm->state).pgc->command_tbl->nr_of_pre) { |
784 if(vmEval_CMD((vm->state).pgc->command_tbl->pre_cmds, | |
785 (vm->state).pgc->command_tbl->nr_of_pre, | |
786 &(vm->state).registers, &link_values)) { | |
0 | 787 /* link_values contains the 'jump' return value */ |
788 return link_values; | |
789 } else { | |
790 fprintf(stderr, "PGC pre commands didn't do a Jump, Link or Call\n"); | |
791 } | |
792 } | |
6 | 793 return play_PG(vm); |
0 | 794 } |
795 | |
796 | |
6 | 797 static link_t play_PG(vm_t *vm) |
0 | 798 { |
6 | 799 fprintf(stderr, "play_PG: (vm->state).pgN (%i)\n", (vm->state).pgN); |
0 | 800 |
6 | 801 assert((vm->state).pgN > 0); |
802 if((vm->state).pgN > (vm->state).pgc->nr_of_programs) { | |
803 fprintf(stderr, "(vm->state).pgN (%i) == pgc->nr_of_programs + 1 (%i)\n", | |
804 (vm->state).pgN, (vm->state).pgc->nr_of_programs + 1); | |
805 assert((vm->state).pgN == (vm->state).pgc->nr_of_programs + 1); | |
806 return play_PGC_post(vm); | |
0 | 807 } |
808 | |
6 | 809 (vm->state).cellN = (vm->state).pgc->program_map[(vm->state).pgN - 1]; |
0 | 810 |
6 | 811 return play_Cell(vm); |
0 | 812 } |
813 | |
814 | |
6 | 815 static link_t play_Cell(vm_t *vm) |
0 | 816 { |
6 | 817 fprintf(stderr, "play_Cell: (vm->state).cellN (%i)\n", (vm->state).cellN); |
0 | 818 |
6 | 819 assert((vm->state).cellN > 0); |
820 if((vm->state).cellN > (vm->state).pgc->nr_of_cells) { | |
821 fprintf(stderr, "(vm->state).cellN (%i) == pgc->nr_of_cells + 1 (%i)\n", | |
822 (vm->state).cellN, (vm->state).pgc->nr_of_cells + 1); | |
823 assert((vm->state).cellN == (vm->state).pgc->nr_of_cells + 1); | |
824 return play_PGC_post(vm); | |
0 | 825 } |
826 | |
827 | |
828 /* Multi angle/Interleaved */ | |
6 | 829 switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode) { |
0 | 830 case 0: /* Normal */ |
6 | 831 assert((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type == 0); |
0 | 832 break; |
833 case 1: /* The first cell in the block */ | |
6 | 834 switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type) { |
0 | 835 case 0: /* Not part of a block */ |
836 assert(0); | |
837 case 1: /* Angle block */ | |
838 /* Loop and check each cell instead? So we don't get outsid the block. */ | |
6 | 839 (vm->state).cellN += (vm->state).AGL_REG - 1; |
840 assert((vm->state).cellN <= (vm->state).pgc->nr_of_cells); | |
841 assert((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode != 0); | |
842 assert((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type == 1); | |
0 | 843 break; |
844 case 2: /* ?? */ | |
845 case 3: /* ?? */ | |
846 default: | |
847 fprintf(stderr, "Invalid? Cell block_mode (%d), block_type (%d)\n", | |
6 | 848 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode, |
849 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type); | |
0 | 850 } |
851 break; | |
852 case 2: /* Cell in the block */ | |
853 case 3: /* Last cell in the block */ | |
854 /* These might perhaps happen for RSM or LinkC commands? */ | |
855 default: | |
856 fprintf(stderr, "Cell is in block but did not enter at first cell!\n"); | |
857 } | |
858 | |
6 | 859 /* Updates (vm->state).pgN and PTTN_REG */ |
860 if(set_PGN(vm)) { | |
0 | 861 /* Should not happen */ |
862 link_t tmp = {LinkTailPGC, /* No Button */ 0, 0, 0}; | |
863 assert(0); | |
864 return tmp; | |
865 } | |
866 | |
867 { | |
868 link_t tmp = {PlayThis, /* Block in Cell */ 0, 0, 0}; | |
869 return tmp; | |
870 } | |
871 | |
872 } | |
873 | |
6 | 874 static link_t play_Cell_post(vm_t *vm) |
0 | 875 { |
876 cell_playback_t *cell; | |
877 | |
6 | 878 fprintf(stderr, "play_Cell_post: (vm->state).cellN (%i)\n", (vm->state).cellN); |
0 | 879 |
6 | 880 cell = &(vm->state).pgc->cell_playback[(vm->state).cellN - 1]; |
0 | 881 |
882 /* Still time is already taken care of before we get called. */ | |
883 | |
884 /* Deal with a Cell command, if any */ | |
885 if(cell->cell_cmd_nr != 0) { | |
886 link_t link_values; | |
887 | |
6 | 888 assert((vm->state).pgc->command_tbl != NULL); |
889 assert((vm->state).pgc->command_tbl->nr_of_cell >= cell->cell_cmd_nr); | |
0 | 890 fprintf(stderr, "Cell command pressent, executing\n"); |
6 | 891 if(vmEval_CMD(&(vm->state).pgc->command_tbl->cell_cmds[cell->cell_cmd_nr - 1], 1, |
892 &(vm->state).registers, &link_values)) { | |
0 | 893 return link_values; |
894 } else { | |
895 fprintf(stderr, "Cell command didn't do a Jump, Link or Call\n"); | |
896 /* Error ?? goto tail? goto next PG? or what? just continue? */ | |
897 } | |
898 } | |
899 | |
900 | |
901 /* Where to continue after playing the cell... */ | |
902 /* Multi angle/Interleaved */ | |
6 | 903 switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode) { |
0 | 904 case 0: /* Normal */ |
6 | 905 assert((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type == 0); |
906 (vm->state).cellN++; | |
0 | 907 break; |
908 case 1: /* The first cell in the block */ | |
909 case 2: /* A cell in the block */ | |
910 case 3: /* The last cell in the block */ | |
911 default: | |
6 | 912 switch((vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type) { |
0 | 913 case 0: /* Not part of a block */ |
914 assert(0); | |
915 case 1: /* Angle block */ | |
916 /* Skip the 'other' angles */ | |
6 | 917 (vm->state).cellN++; |
918 while((vm->state).cellN <= (vm->state).pgc->nr_of_cells | |
919 && (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode >= 2) { | |
920 (vm->state).cellN++; | |
0 | 921 } |
922 break; | |
923 case 2: /* ?? */ | |
924 case 3: /* ?? */ | |
925 default: | |
926 fprintf(stderr, "Invalid? Cell block_mode (%d), block_type (%d)\n", | |
6 | 927 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_mode, |
928 (vm->state).pgc->cell_playback[(vm->state).cellN - 1].block_type); | |
0 | 929 } |
930 break; | |
931 } | |
932 | |
933 | |
934 /* Figure out the correct pgN for the new cell */ | |
6 | 935 if(set_PGN(vm)) { |
0 | 936 fprintf(stderr, "last cell in this PGC\n"); |
6 | 937 return play_PGC_post(vm); |
0 | 938 } |
939 | |
6 | 940 return play_Cell(vm); |
0 | 941 } |
942 | |
943 | |
6 | 944 static link_t play_PGC_post(vm_t *vm) |
0 | 945 { |
946 link_t link_values; | |
947 | |
948 fprintf(stderr, "play_PGC_post:\n"); | |
949 | |
6 | 950 assert((vm->state).pgc->still_time == 0); /* FIXME $$$ */ |
0 | 951 |
952 /* eval -> updates the state and returns either | |
953 - some kind of jump (Jump(TT/SS/VTS_TTN/CallSS/link C/PG/PGC/PTTN) | |
954 - or a error (are there more cases?) | |
955 - if you got to the end of the post_cmds, then what ?? */ | |
6 | 956 if((vm->state).pgc->command_tbl && |
957 vmEval_CMD((vm->state).pgc->command_tbl->post_cmds, | |
958 (vm->state).pgc->command_tbl->nr_of_post, | |
959 &(vm->state).registers, &link_values)) { | |
0 | 960 return link_values; |
961 } | |
962 | |
963 /* Or perhaps handle it here? */ | |
964 { | |
965 link_t link_next_pgc = {LinkNextPGC, 0, 0, 0}; | |
966 fprintf(stderr, "** Fell of the end of the pgc, continuing in NextPGC\n"); | |
6 | 967 assert((vm->state).pgc->next_pgc_nr != 0); |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
968 /* Should end up in the STOP_DOMAIN if next_pgc is 0. */ |
0 | 969 return link_next_pgc; |
970 } | |
971 } | |
972 | |
973 | |
6 | 974 static link_t process_command(vm_t *vm, link_t link_values) |
0 | 975 { |
976 /* FIXME $$$ Move this to a separate function? */ | |
6 | 977 vm->badness_counter++; |
978 if (vm->badness_counter > 1) fprintf(stderr, "**** process_command re-entered %d*****\n",vm->badness_counter); | |
0 | 979 while(link_values.command != PlayThis) { |
980 | |
981 vmPrint_LINK(link_values); | |
982 | |
983 fprintf(stderr, "Link values %i %i %i %i\n", link_values.command, | |
984 link_values.data1, link_values.data2, link_values.data3); | |
985 | |
986 fprintf(stderr, "Before:"); | |
6 | 987 vm_print_current_domain_state(vm); |
0 | 988 |
989 switch(link_values.command) { | |
990 case LinkNoLink: | |
991 /* No Link */ | |
9 | 992 /* BUTTON number:data1 */ |
0 | 993 if(link_values.data1 != 0) |
6 | 994 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
995 fprintf(stderr, "libdvdnav: FIXME: in trouble...LinkNoLink - CRASHING!!!\n"); |
6 | 996 assert(0); |
0 | 997 |
998 case LinkTopC: | |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
999 /* Link to Top?? Cell. What is TopC */ |
9 | 1000 /* BUTTON number:data1 */ |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1001 fprintf(stderr, "libdvdnav: FIXME: LinkTopC. What is LinkTopC?\n"); |
0 | 1002 if(link_values.data1 != 0) |
6 | 1003 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
1004 link_values = play_Cell(vm); | |
0 | 1005 break; |
1006 case LinkNextC: | |
1007 /* Link to Next Cell */ | |
9 | 1008 /* BUTTON number:data1 */ |
0 | 1009 if(link_values.data1 != 0) |
6 | 1010 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1011 (vm->state).cellN += 1; /* if cellN becomes > nr_of_cells? it is handled in play_Cell() */ |
6 | 1012 link_values = play_Cell(vm); |
0 | 1013 break; |
1014 case LinkPrevC: | |
1015 /* Link to Previous Cell */ | |
9 | 1016 /* BUTTON number:data1 */ |
0 | 1017 if(link_values.data1 != 0) |
6 | 1018 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1019 (vm->state).cellN -= 1; /* If cellN becomes < 1? it is handled in play_Cell() */ |
6 | 1020 link_values = play_Cell(vm); |
0 | 1021 break; |
1022 | |
1023 case LinkTopPG: | |
1024 /* Link to Top Program */ | |
9 | 1025 /* BUTTON number:data1 */ |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1026 fprintf(stderr, "libdvdnav: FIXME: LinkTopPG. What is LinkTopPG?\n"); |
0 | 1027 if(link_values.data1 != 0) |
6 | 1028 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
0 | 1029 /* Does pgN always contain the current value? */ |
6 | 1030 link_values = play_PG(vm); |
0 | 1031 break; |
1032 case LinkNextPG: | |
1033 /* Link to Next Program */ | |
9 | 1034 /* BUTTON number:data1 */ |
0 | 1035 if(link_values.data1 != 0) |
6 | 1036 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
0 | 1037 /* Does pgN always contain the current value? */ |
6 | 1038 (vm->state).pgN += 1; /* FIXME: What if pgN becomes > pgc.nr_of_programs? */ |
1039 link_values = play_PG(vm); | |
0 | 1040 break; |
1041 case LinkPrevPG: | |
1042 /* Link to Previous Program */ | |
9 | 1043 /* BUTTON number:data1 */ |
0 | 1044 if(link_values.data1 != 0) |
6 | 1045 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
0 | 1046 /* Does pgN always contain the current value? */ |
9 | 1047 assert((vm->state).pgN > 1); |
6 | 1048 (vm->state).pgN -= 1; /* FIXME: What if pgN becomes < 1? */ |
1049 link_values = play_PG(vm); | |
0 | 1050 break; |
1051 | |
1052 case LinkTopPGC: | |
1053 /* Link to Top Program Chain */ | |
9 | 1054 /* BUTTON number:data1 */ |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1055 fprintf(stderr, "libdvdnav: FIXME: LinkTopPGC. What is LinkTopPGC?\n"); |
0 | 1056 if(link_values.data1 != 0) |
6 | 1057 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
1058 link_values = play_PGC(vm); | |
0 | 1059 break; |
1060 case LinkNextPGC: | |
1061 /* Link to Next Program Chain */ | |
9 | 1062 /* BUTTON number:data1 */ |
0 | 1063 if(link_values.data1 != 0) |
6 | 1064 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
1065 assert((vm->state).pgc->next_pgc_nr != 0); | |
1066 if(get_PGC(vm, (vm->state).pgc->next_pgc_nr)) | |
0 | 1067 assert(0); |
6 | 1068 link_values = play_PGC(vm); |
0 | 1069 break; |
1070 case LinkPrevPGC: | |
1071 /* Link to Previous Program Chain */ | |
9 | 1072 /* BUTTON number:data1 */ |
0 | 1073 if(link_values.data1 != 0) |
6 | 1074 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
1075 assert((vm->state).pgc->prev_pgc_nr != 0); | |
1076 if(get_PGC(vm, (vm->state).pgc->prev_pgc_nr)) | |
0 | 1077 assert(0); |
6 | 1078 link_values = play_PGC(vm); |
0 | 1079 break; |
1080 case LinkGoUpPGC: | |
1081 /* Link to GoUp??? Program Chain */ | |
9 | 1082 /* BUTTON number:data1 */ |
0 | 1083 if(link_values.data1 != 0) |
6 | 1084 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
1085 assert((vm->state).pgc->goup_pgc_nr != 0); | |
1086 if(get_PGC(vm, (vm->state).pgc->goup_pgc_nr)) | |
0 | 1087 assert(0); |
6 | 1088 link_values = play_PGC(vm); |
0 | 1089 break; |
1090 case LinkTailPGC: | |
1091 /* Link to Tail??? Program Chain */ | |
9 | 1092 /* BUTTON number:data1 */ |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1093 fprintf(stderr, "libdvdnav: FIXME: LinkTailPGC. What is LinkTailPGC?\n"); |
0 | 1094 if(link_values.data1 != 0) |
6 | 1095 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
1096 link_values = play_PGC_post(vm); | |
0 | 1097 break; |
1098 | |
1099 case LinkRSM: | |
1100 { | |
1101 /* Link to Resume */ | |
1102 int i; | |
1103 /* Check and see if there is any rsm info!! */ | |
6 | 1104 (vm->state).domain = VTS_DOMAIN; |
1105 ifoOpenNewVTSI(vm, vm->dvd, (vm->state).rsm_vtsN); | |
1106 get_PGC(vm, (vm->state).rsm_pgcN); | |
0 | 1107 |
1108 /* These should never be set in SystemSpace and/or MenuSpace */ | |
6 | 1109 /* (vm->state).TTN_REG = rsm_tt; ?? */ |
1110 /* (vm->state).TT_PGCN_REG = (vm->state).rsm_pgcN; ?? */ | |
0 | 1111 for(i = 0; i < 5; i++) { |
6 | 1112 (vm->state).registers.SPRM[4 + i] = (vm->state).rsm_regs[i]; |
0 | 1113 } |
1114 | |
1115 if(link_values.data1 != 0) | |
6 | 1116 (vm->state).HL_BTNN_REG = link_values.data1 << 10; |
0 | 1117 |
6 | 1118 if((vm->state).rsm_cellN == 0) { |
1119 assert((vm->state).cellN); /* Checking if this ever happens */ | |
0 | 1120 /* assert( time/block/vobu is 0 ); */ |
6 | 1121 (vm->state).pgN = 1; |
1122 link_values = play_PG(vm); | |
0 | 1123 } else { |
1124 /* assert( time/block/vobu is _not_ 0 ); */ | |
1125 /* play_Cell_at_time */ | |
6 | 1126 /* (vm->state).pgN = ?? this gets the righ value in play_Cell */ |
1127 (vm->state).cellN = (vm->state).rsm_cellN; | |
0 | 1128 link_values.command = PlayThis; |
6 | 1129 link_values.data1 = (vm->state).rsm_blockN; |
1130 if(set_PGN(vm)) { | |
0 | 1131 /* Were at the end of the PGC, should not happen for a RSM */ |
1132 assert(0); | |
1133 link_values.command = LinkTailPGC; | |
1134 link_values.data1 = 0; /* No button */ | |
1135 } | |
1136 } | |
1137 } | |
1138 break; | |
1139 case LinkPGCN: | |
1140 /* Link to Program Chain Number:data1 */ | |
6 | 1141 if(get_PGC(vm, link_values.data1)) |
0 | 1142 assert(0); |
6 | 1143 link_values = play_PGC(vm); |
0 | 1144 break; |
1145 case LinkPTTN: | |
1146 /* Link to Part of this Title Number:data1 */ | |
9 | 1147 /* BUTTON number:data2 */ |
6 | 1148 assert((vm->state).domain == VTS_DOMAIN); |
0 | 1149 if(link_values.data2 != 0) |
6 | 1150 (vm->state).HL_BTNN_REG = link_values.data2 << 10; |
1151 if(get_VTS_PTT(vm, (vm->state).vtsN, (vm->state).VTS_TTN_REG, link_values.data1) == -1) | |
0 | 1152 assert(0); |
6 | 1153 link_values = play_PG(vm); |
0 | 1154 break; |
1155 case LinkPGN: | |
1156 /* Link to Program Number:data1 */ | |
9 | 1157 /* BUTTON number:data2 */ |
0 | 1158 if(link_values.data2 != 0) |
6 | 1159 (vm->state).HL_BTNN_REG = link_values.data2 << 10; |
0 | 1160 /* Update any other state, PTTN perhaps? */ |
6 | 1161 (vm->state).pgN = link_values.data1; |
1162 link_values = play_PG(vm); | |
0 | 1163 break; |
1164 case LinkCN: | |
1165 /* Link to Cell Number:data1 */ | |
9 | 1166 /* BUTTON number:data2 */ |
0 | 1167 if(link_values.data2 != 0) |
6 | 1168 (vm->state).HL_BTNN_REG = link_values.data2 << 10; |
0 | 1169 /* Update any other state, pgN, PTTN perhaps? */ |
6 | 1170 (vm->state).cellN = link_values.data1; |
1171 link_values = play_Cell(vm); | |
0 | 1172 break; |
1173 | |
1174 case Exit: | |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1175 fprintf(stderr, "libdvdnav: FIXME:in trouble...Link Exit - CRASHING!!!\n"); |
6 | 1176 assert(0); /* What should we do here?? */ |
0 | 1177 |
1178 case JumpTT: | |
1179 /* Jump to VTS Title Domain */ | |
1180 /* Only allowed from the First Play domain(PGC) */ | |
1181 /* or the Video Manager domain (VMG) */ | |
1182 //fprintf(stderr,"****** JumpTT is Broken, please fix me!!! ****\n"); | |
6 | 1183 assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN); /* ?? */ |
1184 if(get_TT(vm,link_values.data1) == -1) | |
0 | 1185 assert(0); |
6 | 1186 link_values = play_PGC(vm); |
0 | 1187 break; |
1188 case JumpVTS_TT: | |
1189 /* Jump to Title:data1 in same VTS Title Domain */ | |
1190 /* Only allowed from the VTS Menu Domain(VTSM) */ | |
1191 /* or the Video Title Set Domain(VTS) */ | |
6 | 1192 assert((vm->state).domain == VTSM_DOMAIN || (vm->state).domain == VTS_DOMAIN); /* ?? */ |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1193 fprintf(stderr, "libdvdnav: FIXME: Should be able to use get_VTS_PTT here.\n"); |
6 | 1194 if(get_VTS_TT(vm,(vm->state).vtsN, link_values.data1) == -1) |
0 | 1195 assert(0); |
6 | 1196 link_values = play_PGC(vm); |
0 | 1197 break; |
1198 case JumpVTS_PTT: | |
1199 /* Jump to Part:data2 of Title:data1 in same VTS Title Domain */ | |
1200 /* Only allowed from the VTS Menu Domain(VTSM) */ | |
1201 /* or the Video Title Set Domain(VTS) */ | |
6 | 1202 assert((vm->state).domain == VTSM_DOMAIN || (vm->state).domain == VTS_DOMAIN); /* ?? */ |
1203 if(get_VTS_PTT(vm,(vm->state).vtsN, link_values.data1, link_values.data2) == -1) | |
0 | 1204 assert(0); |
6 | 1205 link_values = play_PG(vm); |
0 | 1206 break; |
1207 | |
1208 case JumpSS_FP: | |
1209 /* Jump to First Play Domain */ | |
1210 /* Only allowed from the VTS Menu Domain(VTSM) */ | |
1211 /* or the Video Manager domain (VMG) */ | |
6 | 1212 assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == VTSM_DOMAIN); /* ?? */ |
1213 get_FP_PGC(vm); | |
1214 link_values = play_PGC(vm); | |
0 | 1215 break; |
1216 case JumpSS_VMGM_MENU: | |
1217 /* Jump to Video Manger domain - Title Menu:data1 or any PGC in VMG */ | |
1218 /* Allowed from anywhere except the VTS Title domain */ | |
6 | 1219 assert((vm->state).domain == VMGM_DOMAIN || |
1220 (vm->state).domain == VTSM_DOMAIN || | |
1221 (vm->state).domain == FP_DOMAIN); /* ?? */ | |
1222 (vm->state).domain = VMGM_DOMAIN; | |
1223 if(get_MENU(vm,link_values.data1) == -1) | |
0 | 1224 assert(0); |
6 | 1225 link_values = play_PGC(vm); |
0 | 1226 break; |
1227 case JumpSS_VTSM: | |
1228 /* Jump to a menu in Video Title domain, */ | |
1229 /* or to a Menu is the current VTS */ | |
1230 /* FIXME: This goes badly wrong for some DVDs. */ | |
1231 /* FIXME: Keep in touch with ogle people regarding what to do here */ | |
9 | 1232 /* ifoOpenNewVTSI:data1 */ |
1233 /* VTS_TTN_REG:data2 */ | |
1234 /* get_MENU:data3 */ | |
0 | 1235 fprintf(stderr, "dvdnav: BUG TRACKING *******************************************************************\n"); |
1236 fprintf(stderr, " data1=%u data2=%u data3=%u\n", | |
1237 link_values.data1, | |
1238 link_values.data2, | |
1239 link_values.data3); | |
1240 fprintf(stderr, "dvdnav: *******************************************************************\n"); | |
1241 | |
1242 if(link_values.data1 !=0) { | |
6 | 1243 assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == FP_DOMAIN); /* ?? */ |
1244 (vm->state).domain = VTSM_DOMAIN; | |
1245 ifoOpenNewVTSI(vm, vm->dvd, link_values.data1); /* Also sets (vm->state).vtsN */ | |
0 | 1246 } else { |
1247 /* This happens on 'The Fifth Element' region 2. */ | |
6 | 1248 assert((vm->state).domain == VTSM_DOMAIN); |
0 | 1249 } |
1250 /* I don't know what title is supposed to be used for. */ | |
1251 /* Alien or Aliens has this != 1, I think. */ | |
1252 /* assert(link_values.data2 == 1); */ | |
6 | 1253 (vm->state).VTS_TTN_REG = link_values.data2; |
1254 if(get_MENU(vm, link_values.data3) == -1) | |
0 | 1255 assert(0); |
6 | 1256 link_values = play_PGC(vm); |
0 | 1257 break; |
1258 case JumpSS_VMGM_PGC: | |
9 | 1259 /* get_PGC:data1 */ |
6 | 1260 assert((vm->state).domain == VMGM_DOMAIN || |
1261 (vm->state).domain == VTSM_DOMAIN || | |
1262 (vm->state).domain == FP_DOMAIN); /* ?? */ | |
1263 (vm->state).domain = VMGM_DOMAIN; | |
1264 if(get_PGC(vm,link_values.data1) == -1) | |
0 | 1265 assert(0); |
6 | 1266 link_values = play_PGC(vm); |
0 | 1267 break; |
1268 | |
1269 case CallSS_FP: | |
9 | 1270 /* saveRSMinfo:data1 */ |
6 | 1271 assert((vm->state).domain == VTS_DOMAIN); /* ?? */ |
0 | 1272 /* Must be called before domain is changed */ |
6 | 1273 saveRSMinfo(vm, link_values.data1, /* We dont have block info */ 0); |
1274 get_FP_PGC(vm); | |
1275 link_values = play_PGC(vm); | |
0 | 1276 break; |
1277 case CallSS_VMGM_MENU: | |
9 | 1278 /* get_MENU:data1 */ |
1279 /* saveRSMinfo:data2 */ | |
6 | 1280 assert((vm->state).domain == VTS_DOMAIN); /* ?? */ |
0 | 1281 /* Must be called before domain is changed */ |
6 | 1282 saveRSMinfo(vm,link_values.data2, /* We dont have block info */ 0); |
1283 (vm->state).domain = VMGM_DOMAIN; | |
1284 if(get_MENU(vm,link_values.data1) == -1) | |
0 | 1285 assert(0); |
6 | 1286 link_values = play_PGC(vm); |
0 | 1287 break; |
1288 case CallSS_VTSM: | |
9 | 1289 /* get_MENU:data1 */ |
1290 /* saveRSMinfo:data2 */ | |
6 | 1291 assert((vm->state).domain == VTS_DOMAIN); /* ?? */ |
0 | 1292 /* Must be called before domain is changed */ |
6 | 1293 saveRSMinfo(vm,link_values.data2, /* We dont have block info */ 0); |
1294 (vm->state).domain = VTSM_DOMAIN; | |
1295 if(get_MENU(vm,link_values.data1) == -1) | |
0 | 1296 assert(0); |
6 | 1297 link_values = play_PGC(vm); |
0 | 1298 break; |
1299 case CallSS_VMGM_PGC: | |
9 | 1300 /* get_PGC:data1 */ |
1301 /* saveRSMinfo:data2 */ | |
6 | 1302 assert((vm->state).domain == VTS_DOMAIN); /* ?? */ |
0 | 1303 /* Must be called before domain is changed */ |
6 | 1304 saveRSMinfo(vm,link_values.data2, /* We dont have block info */ 0); |
1305 (vm->state).domain = VMGM_DOMAIN; | |
1306 if(get_PGC(vm,link_values.data1) == -1) | |
0 | 1307 assert(0); |
6 | 1308 link_values = play_PGC(vm); |
0 | 1309 break; |
1310 case PlayThis: | |
1311 /* Should never happen. */ | |
9 | 1312 assert(0); |
0 | 1313 break; |
1314 } | |
1315 fprintf(stderr, "After:"); | |
6 | 1316 vm_print_current_domain_state(vm); |
0 | 1317 |
1318 } | |
6 | 1319 vm->badness_counter--; |
0 | 1320 return link_values; |
1321 } | |
1322 | |
14 | 1323 /* Searches the TT tables, to find the current TT. |
1324 * returns the current TT. | |
1325 * returns 0 if not found. | |
1326 */ | |
1327 static int find_TT(vm_t *vm, int vtsN, int vts_ttn) { | |
1328 int i; | |
1329 int tt=0; | |
1330 for(i = 1; i <= vm->vmgi->tt_srpt->nr_of_srpts; i++) { | |
1331 if( vm->vmgi->tt_srpt->title[i - 1].title_set_nr == vtsN && | |
1332 vm->vmgi->tt_srpt->title[i - 1].vts_ttn == vts_ttn) { | |
1333 tt=i; | |
1334 break; | |
1335 } | |
1336 } | |
1337 return tt; | |
1338 } | |
1339 | |
6 | 1340 static int get_TT(vm_t *vm, int tt) |
0 | 1341 { |
1342 //fprintf(stderr,"****** get_TT is Broken, please fix me!!! ****\n"); | |
6 | 1343 assert(tt <= vm->vmgi->tt_srpt->nr_of_srpts); |
0 | 1344 |
6 | 1345 (vm->state).TTN_REG = tt; |
0 | 1346 |
6 | 1347 return get_VTS_TT(vm, vm->vmgi->tt_srpt->title[tt - 1].title_set_nr, |
1348 vm->vmgi->tt_srpt->title[tt - 1].vts_ttn); | |
0 | 1349 } |
1350 | |
1351 | |
6 | 1352 static int get_VTS_TT(vm_t *vm, int vtsN, int vts_ttn) |
0 | 1353 { |
14 | 1354 fprintf(stderr, "get_VTS_TT called, testing!!! vtsN=%d, vts_ttn=%d\n", vtsN, vts_ttn); |
1355 return get_VTS_PTT(vm, vtsN, vts_ttn, 1); | |
1356 //pgcN = get_ID(vm, vts_ttn); /* This might return -1 */ | |
1357 //assert(pgcN != -1); | |
0 | 1358 |
14 | 1359 //(vm->state).TTN_REG = find_TT(*vm, vtsN, vts_ttn); |
1360 //(vm->state).VTS_TTN_REG = vts_ttn; | |
1361 //(vm->state).vtsN = | |
0 | 1362 /* Any other registers? */ |
1363 | |
14 | 1364 //return get_PGC(vm, pgcN); |
0 | 1365 } |
1366 | |
1367 | |
6 | 1368 static int get_VTS_PTT(vm_t *vm, int vtsN, int /* is this really */ vts_ttn, int part) |
0 | 1369 { |
1370 int pgcN, pgN; | |
1371 | |
6 | 1372 (vm->state).domain = VTS_DOMAIN; |
1373 if(vtsN != (vm->state).vtsN) | |
1374 ifoOpenNewVTSI(vm, vm->dvd, vtsN); /* Also sets (vm->state).vtsN */ | |
0 | 1375 |
6 | 1376 assert(vts_ttn <= vm->vtsi->vts_ptt_srpt->nr_of_srpts); |
1377 assert(part <= vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].nr_of_ptts); | |
0 | 1378 |
6 | 1379 pgcN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgcn; |
1380 pgN = vm->vtsi->vts_ptt_srpt->title[vts_ttn - 1].ptt[part - 1].pgn; | |
14 | 1381 |
1382 (vm->state).TT_PGCN_REG = pgcN; | |
1383 (vm->state).PTTN_REG = pgN; | |
1384 | |
1385 (vm->state).TTN_REG = find_TT(vm, vtsN, vts_ttn); | |
1386 assert( (vm->state.TTN_REG) != 0 ); | |
6 | 1387 (vm->state).VTS_TTN_REG = vts_ttn; |
14 | 1388 (vm->state).vtsN = vtsN; /* Not sure about this one. We can get to it easily from TTN_REG */ |
0 | 1389 /* Any other registers? */ |
1390 | |
6 | 1391 (vm->state).pgN = pgN; /* ?? */ |
0 | 1392 |
6 | 1393 return get_PGC(vm, pgcN); |
0 | 1394 } |
1395 | |
1396 | |
1397 | |
6 | 1398 static int get_FP_PGC(vm_t *vm) |
0 | 1399 { |
6 | 1400 (vm->state).domain = FP_DOMAIN; |
0 | 1401 |
6 | 1402 (vm->state).pgc = vm->vmgi->first_play_pgc; |
0 | 1403 |
1404 return 0; | |
1405 } | |
1406 | |
1407 | |
6 | 1408 static int get_MENU(vm_t *vm, int menu) |
0 | 1409 { |
6 | 1410 assert((vm->state).domain == VMGM_DOMAIN || (vm->state).domain == VTSM_DOMAIN); |
1411 return get_PGC(vm, get_ID(vm, menu)); | |
0 | 1412 } |
1413 | |
6 | 1414 static int get_ID(vm_t *vm, int id) |
0 | 1415 { |
1416 int pgcN, i; | |
1417 pgcit_t *pgcit; | |
1418 | |
1419 /* Relies on state to get the correct pgcit. */ | |
6 | 1420 pgcit = get_PGCIT(vm); |
0 | 1421 assert(pgcit != NULL); |
1422 | |
1423 /* Get menu/title */ | |
1424 for(i = 0; i < pgcit->nr_of_pgci_srp; i++) { | |
1425 if((pgcit->pgci_srp[i].entry_id & 0x7f) == id) { | |
1426 assert((pgcit->pgci_srp[i].entry_id & 0x80) == 0x80); | |
1427 pgcN = i + 1; | |
1428 return pgcN; | |
1429 } | |
1430 } | |
1431 fprintf(stderr, "** No such id/menu (%d) entry PGC\n", id); | |
1432 return -1; /* error */ | |
1433 } | |
1434 | |
1435 | |
1436 | |
6 | 1437 static int get_PGC(vm_t *vm, int pgcN) |
0 | 1438 { |
1439 /* FIXME: Keep this up to date with the ogle people */ | |
1440 pgcit_t *pgcit; | |
1441 | |
6 | 1442 pgcit = get_PGCIT(vm); |
0 | 1443 |
1444 assert(pgcit != NULL); /* ?? Make this return -1 instead */ | |
1445 if(pgcN < 1 || pgcN > pgcit->nr_of_pgci_srp) { | |
1446 /* if(pgcit->nr_of_pgci_srp != 1) */ | |
1447 return -1; /* error */ | |
1448 /* pgcN = 1; */ | |
1449 } | |
1450 | |
6 | 1451 /* (vm->state).pgcN = pgcN; */ |
1452 (vm->state).pgc = pgcit->pgci_srp[pgcN - 1].pgc; | |
0 | 1453 |
6 | 1454 if((vm->state).domain == VTS_DOMAIN) |
1455 (vm->state).TT_PGCN_REG = pgcN; | |
0 | 1456 |
1457 return 0; | |
1458 } | |
1459 | |
6 | 1460 static int get_PGCN(vm_t *vm) |
0 | 1461 { |
1462 pgcit_t *pgcit; | |
1463 int pgcN = 1; | |
1464 | |
6 | 1465 pgcit = get_PGCIT(vm); |
0 | 1466 |
1467 assert(pgcit != NULL); | |
1468 | |
1469 while(pgcN <= pgcit->nr_of_pgci_srp) { | |
6 | 1470 if(pgcit->pgci_srp[pgcN - 1].pgc == (vm->state).pgc) |
0 | 1471 return pgcN; |
1472 pgcN++; | |
1473 } | |
1474 | |
1475 return -1; /* error */ | |
1476 } | |
1477 | |
6 | 1478 static int get_video_aspect(vm_t *vm) |
0 | 1479 { |
1480 int aspect = 0; | |
1481 | |
6 | 1482 if((vm->state).domain == VTS_DOMAIN) { |
1483 aspect = vm->vtsi->vtsi_mat->vts_video_attr.display_aspect_ratio; | |
1484 } else if((vm->state).domain == VTSM_DOMAIN) { | |
1485 aspect = vm->vtsi->vtsi_mat->vtsm_video_attr.display_aspect_ratio; | |
1486 } else if((vm->state).domain == VMGM_DOMAIN) { | |
1487 aspect = vm->vmgi->vmgi_mat->vmgm_video_attr.display_aspect_ratio; | |
0 | 1488 } |
1489 fprintf(stderr, "dvdnav:get_video_aspect:aspect=%d\n",aspect); | |
1490 assert(aspect == 0 || aspect == 3); | |
6 | 1491 (vm->state).registers.SPRM[14] &= ~(0x3 << 10); |
1492 (vm->state).registers.SPRM[14] |= aspect << 10; | |
0 | 1493 |
1494 return aspect; | |
1495 } | |
1496 | |
6 | 1497 static void ifoOpenNewVTSI(vm_t *vm, dvd_reader_t *dvd, int vtsN) |
0 | 1498 { |
6 | 1499 if((vm->state).vtsN == vtsN) { |
0 | 1500 return; /* We alread have it */ |
1501 } | |
1502 | |
6 | 1503 if(vm->vtsi != NULL) |
1504 ifoClose(vm->vtsi); | |
0 | 1505 |
6 | 1506 vm->vtsi = ifoOpenVTSI(dvd, vtsN); |
1507 if(vm->vtsi == NULL) { | |
1508 fprintf(stderr, "ifoOpenVTSI failed - CRASHING!!!\n"); | |
1509 assert(0); | |
0 | 1510 } |
6 | 1511 if(!ifoRead_VTS_PTT_SRPT(vm->vtsi)) { |
1512 fprintf(stderr, "ifoRead_VTS_PTT_SRPT failed - CRASHING!!!\n"); | |
1513 assert(0); | |
0 | 1514 } |
6 | 1515 if(!ifoRead_PGCIT(vm->vtsi)) { |
1516 fprintf(stderr, "ifoRead_PGCIT failed - CRASHING!!!\n"); | |
1517 assert(0); | |
0 | 1518 } |
6 | 1519 if(!ifoRead_PGCI_UT(vm->vtsi)) { |
1520 fprintf(stderr, "ifoRead_PGCI_UT failed - CRASHING!!!\n"); | |
1521 assert(0); | |
0 | 1522 } |
6 | 1523 if(!ifoRead_VOBU_ADMAP(vm->vtsi)) { |
1524 fprintf(stderr, "ifoRead_VOBU_ADMAP vtsi failed - CRASHING\n"); | |
1525 assert(0); | |
0 | 1526 } |
6 | 1527 if(!ifoRead_TITLE_VOBU_ADMAP(vm->vtsi)) { |
1528 fprintf(stderr, "ifoRead_TITLE_VOBU_ADMAP vtsi failed - CRASHING\n"); | |
1529 assert(0); | |
0 | 1530 } |
6 | 1531 (vm->state).vtsN = vtsN; |
0 | 1532 } |
1533 | |
6 | 1534 static pgcit_t* get_MENU_PGCIT(vm_t *vm, ifo_handle_t *h, uint16_t lang) |
0 | 1535 { |
1536 int i; | |
1537 | |
1538 if(h == NULL || h->pgci_ut == NULL) { | |
1539 fprintf(stderr, "*** pgci_ut handle is NULL ***\n"); | |
1540 return NULL; /* error? */ | |
1541 } | |
1542 | |
1543 i = 0; | |
1544 while(i < h->pgci_ut->nr_of_lus | |
1545 && h->pgci_ut->lu[i].lang_code != lang) | |
1546 i++; | |
1547 if(i == h->pgci_ut->nr_of_lus) { | |
1548 fprintf(stderr, "Language '%c%c' not found, using '%c%c' instead\n", | |
1549 (char)(lang >> 8), (char)(lang & 0xff), | |
1550 (char)(h->pgci_ut->lu[0].lang_code >> 8), | |
1551 (char)(h->pgci_ut->lu[0].lang_code & 0xff)); | |
1552 i = 0; /* error? */ | |
1553 } | |
1554 | |
1555 return h->pgci_ut->lu[i].pgcit; | |
1556 } | |
1557 | |
1558 /* Uses state to decide what to return */ | |
6 | 1559 static pgcit_t* get_PGCIT(vm_t *vm) { |
0 | 1560 pgcit_t *pgcit; |
1561 | |
6 | 1562 if((vm->state).domain == VTS_DOMAIN) { |
1563 pgcit = vm->vtsi->vts_pgcit; | |
1564 } else if((vm->state).domain == VTSM_DOMAIN) { | |
1565 pgcit = get_MENU_PGCIT(vm, vm->vtsi, (vm->state).registers.SPRM[0]); | |
1566 } else if((vm->state).domain == VMGM_DOMAIN) { | |
1567 pgcit = get_MENU_PGCIT(vm, vm->vmgi, (vm->state).registers.SPRM[0]); | |
0 | 1568 } else { |
1569 pgcit = NULL; /* Should never hapen */ | |
1570 } | |
1571 | |
1572 return pgcit; | |
1573 } | |
1574 | |
1575 /* | |
1576 * $Log$ | |
19
7e8628911b4f
Implement General Register Counters or GPRM counters.
jcdutton
parents:
18
diff
changeset
|
1577 * Revision 1.11 2002/04/12 20:06:41 jcdutton |
7e8628911b4f
Implement General Register Counters or GPRM counters.
jcdutton
parents:
18
diff
changeset
|
1578 * Implement General Register Counters or GPRM counters. |
7e8628911b4f
Implement General Register Counters or GPRM counters.
jcdutton
parents:
18
diff
changeset
|
1579 * Navigation timers are not supported yet. SPRM[9] and SPRM[10]. |
7e8628911b4f
Implement General Register Counters or GPRM counters.
jcdutton
parents:
18
diff
changeset
|
1580 * |
18 | 1581 * Revision 1.10 2002/04/12 12:43:36 jcdutton |
1582 * Display DVD disk region setting. | |
1583 * Display possible RCE region protection message. | |
1584 * | |
17 | 1585 * Revision 1.9 2002/04/10 16:45:57 jcdutton |
1586 * Actually fix the const this time! | |
1587 * | |
16 | 1588 * Revision 1.8 2002/04/10 16:40:52 jcdutton |
1589 * Fix a const problem. | |
1590 * | |
14 | 1591 * Revision 1.7 2002/04/10 13:09:40 jcdutton |
1592 * Some improvements to decoder.c | |
1593 * Registers should be updated correctly now, but still needs checking. | |
1594 * | |
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1595 * Revision 1.6 2002/04/09 15:19:07 jcdutton |
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1596 * Added some debug info, to hopefully help in tracking bugs in libdvdnav. |
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
9
diff
changeset
|
1597 * |
9 | 1598 * Revision 1.5 2002/04/07 19:35:54 jcdutton |
1599 * Added some comments into the code. | |
1600 * | |
6 | 1601 * Revision 1.4 2002/04/06 18:31:50 jcdutton |
1602 * Some cleaning up. | |
1603 * changed exit(1) to assert(0) so they actually get seen by the user so that it helps developers more. | |
1604 * | |
4
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
1605 * Revision 1.3 2002/04/02 18:22:27 richwareham |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
1606 * Added reset patch from Kees Cook <kees@outflux.net> |
99bed5d6db2f
Added reset patch from Kees Cook <kees@outflux.net>
richwareham
parents:
3
diff
changeset
|
1607 * |
3
328eadb3f37e
Added initial example programs directory and make sure all debug/error output goes to stderr.
richwareham
parents:
0
diff
changeset
|
1608 * Revision 1.2 2002/04/01 18:56:28 richwareham |
328eadb3f37e
Added initial example programs directory and make sure all debug/error output goes to stderr.
richwareham
parents:
0
diff
changeset
|
1609 * Added initial example programs directory and make sure all debug/error output goes to stderr. |
328eadb3f37e
Added initial example programs directory and make sure all debug/error output goes to stderr.
richwareham
parents:
0
diff
changeset
|
1610 * |
328eadb3f37e
Added initial example programs directory and make sure all debug/error output goes to stderr.
richwareham
parents:
0
diff
changeset
|
1611 * Revision 1.1.1.1 2002/03/12 19:45:55 richwareham |
328eadb3f37e
Added initial example programs directory and make sure all debug/error output goes to stderr.
richwareham
parents:
0
diff
changeset
|
1612 * Initial import |
0 | 1613 * |
1614 * Revision 1.18 2002/01/22 16:56:49 jcdutton | |
1615 * Fix clut after seeking. | |
6 | 1616 * Add a few virtual machine debug messages, to help diagnose problems with "Deep Purple - Total Abandon" DVD as I don't have the DVD itvm. |
0 | 1617 * Fix a few debug messages, so they do not say FIXME. |
1618 * Move the FIXME debug messages to comments in the code. | |
1619 * | |
1620 * Revision 1.17 2002/01/21 01:16:30 jcdutton | |
1621 * Added some debug messages, to hopefully get info from users. | |
1622 * | |
1623 * Revision 1.16 2002/01/20 21:40:46 jcdutton | |
1624 * Start to fix some assert failures. | |
1625 * | |
1626 * Revision 1.15 2002/01/19 20:24:38 jcdutton | |
1627 * Just some FIXME notes added. | |
1628 * | |
1629 * Revision 1.14 2002/01/13 22:17:57 jcdutton | |
1630 * Change logging. | |
1631 * | |
1632 * | |
1633 */ |