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