comparison vm/decoder.c @ 0:427b7da5cbdb src

first split of dvdread; it's just a copy of dvdnav still to be cleaned
author nicodvb
date Sun, 01 Jun 2008 08:39:07 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:427b7da5cbdb
1 /*
2 * Copyright (C) 2000, 2001 Martin Norbäck, Håkan Hjort
3 * 2002-2004 the dvdnav project
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 <stdlib.h>
32 #include <inttypes.h>
33 #include <limits.h>
34 #include <string.h> /* For memset */
35 #include <sys/time.h>
36 #include "nav_types.h"
37 #include "ifo_types.h" /* vm_cmd_t */
38
39 #include "dvd_types.h"
40 #include "remap.h"
41 #include "decoder.h"
42 #include "vm.h"
43 #include "vmcmd.h"
44 #include "dvdnav.h"
45 #include "dvdnav_internal.h"
46
47 uint32_t vm_getbits(command_t *command, int32_t start, int32_t count) {
48 uint64_t result = 0;
49 uint64_t bit_mask = 0;
50 uint64_t examining = 0;
51 int32_t bits;
52
53 if (count == 0) return 0;
54
55 if ( ((start - count) < -1) ||
56 (count > 32) ||
57 (start > 63) ||
58 (count < 0) ||
59 (start < 0) ) {
60 fprintf(MSG_OUT, "libdvdnav: Bad call to vm_getbits. Parameter out of range\n");
61 abort();
62 }
63 /* all ones, please */
64 bit_mask = ~bit_mask;
65 bit_mask >>= 63 - start;
66 bits = start + 1 - count;
67 examining = ((bit_mask >> bits) << bits );
68 command->examined |= examining;
69 result = (command->instruction & bit_mask) >> bits;
70 return (uint32_t) result;
71 }
72
73 static uint16_t get_GPRM(registers_t* registers, uint8_t reg) {
74 if (registers->GPRM_mode[reg] & 0x01) {
75 struct timeval current_time, time_offset;
76 uint16_t result;
77 /* Counter mode */
78 /* fprintf(MSG_OUT, "libdvdnav: Getting counter %d\n",reg);*/
79 gettimeofday(&current_time, NULL);
80 time_offset.tv_sec = current_time.tv_sec - registers->GPRM_time[reg].tv_sec;
81 time_offset.tv_usec = current_time.tv_usec - registers->GPRM_time[reg].tv_usec;
82 if (time_offset.tv_usec < 0) {
83 time_offset.tv_sec--;
84 time_offset.tv_usec += 1000000;
85 }
86 result = (uint16_t) (time_offset.tv_sec & 0xffff);
87 registers->GPRM[reg]=result;
88 return result;
89
90 } else {
91 /* Register mode */
92 return registers->GPRM[reg];
93 }
94
95 }
96
97 static void set_GPRM(registers_t* registers, uint8_t reg, uint16_t value) {
98 if (registers->GPRM_mode[reg] & 0x01) {
99 struct timeval current_time;
100 /* Counter mode */
101 /* fprintf(MSG_OUT, "libdvdnav: Setting counter %d\n",reg); */
102 gettimeofday(&current_time, NULL);
103 registers->GPRM_time[reg] = current_time;
104 registers->GPRM_time[reg].tv_sec -= value;
105 }
106 registers->GPRM[reg] = value;
107 }
108
109 /* Eval register code, can either be system or general register.
110 SXXX_XXXX, where S is 1 if it is system register. */
111 static uint16_t eval_reg(command_t* command, uint8_t reg) {
112 if(reg & 0x80) {
113 if ((reg & 0x1f) == 20) {
114 fprintf(MSG_OUT, "libdvdnav: Suspected RCE Region Protection!!!\n");
115 }
116 return command->registers->SPRM[reg & 0x1f]; /* FIXME max 24 not 32 */
117 } else {
118 return get_GPRM(command->registers, reg & 0x0f) ;
119 }
120 }
121
122 /* Eval register or immediate data.
123 AAAA_AAAA BBBB_BBBB, if immediate use all 16 bits for data else use
124 lower eight bits for the system or general purpose register. */
125 static uint16_t eval_reg_or_data(command_t* command, int32_t imm, int32_t start) {
126 if(imm) { /* immediate */
127 return vm_getbits(command, start, 16);
128 } else {
129 return eval_reg(command, vm_getbits(command, (start - 8), 8));
130 }
131 }
132
133 /* Eval register or immediate data.
134 xBBB_BBBB, if immediate use all 7 bits for data else use
135 lower four bits for the general purpose register number. */
136 /* Evaluates gprm or data depending on bit, data is in byte n */
137 static uint16_t eval_reg_or_data_2(command_t* command,
138 int32_t imm, int32_t start) {
139 if(imm) /* immediate */
140 return vm_getbits(command, (start - 1), 7);
141 else
142 return get_GPRM(command->registers, (vm_getbits(command, (start - 4), 4)) );
143 }
144
145
146 /* Compare data using operation, return result from comparison.
147 Helper function for the different if functions. */
148 static int32_t eval_compare(uint8_t operation, uint16_t data1, uint16_t data2) {
149 switch(operation) {
150 case 1:
151 return data1 & data2;
152 case 2:
153 return data1 == data2;
154 case 3:
155 return data1 != data2;
156 case 4:
157 return data1 >= data2;
158 case 5:
159 return data1 > data2;
160 case 6:
161 return data1 <= data2;
162 case 7:
163 return data1 < data2;
164 }
165 fprintf(MSG_OUT, "libdvdnav: eval_compare: Invalid comparison code\n");
166 return 0;
167 }
168
169
170 /* Evaluate if version 1.
171 Has comparison data in byte 3 and 4-5 (immediate or register) */
172 static int32_t eval_if_version_1(command_t* command) {
173 uint8_t op = vm_getbits(command, 54, 3);
174 if(op) {
175 return eval_compare(op, eval_reg(command, vm_getbits(command, 39, 8)),
176 eval_reg_or_data(command, vm_getbits(command, 55, 1), 31));
177 }
178 return 1;
179 }
180
181 /* Evaluate if version 2.
182 This version only compares register which are in byte 6 and 7 */
183 static int32_t eval_if_version_2(command_t* command) {
184 uint8_t op = vm_getbits(command, 54, 3);
185 if(op) {
186 return eval_compare(op, eval_reg(command, vm_getbits(command, 15, 8)),
187 eval_reg(command, vm_getbits(command, 7, 8)));
188 }
189 return 1;
190 }
191
192 /* Evaluate if version 3.
193 Has comparison data in byte 2 and 6-7 (immediate or register) */
194 static int32_t eval_if_version_3(command_t* command) {
195 uint8_t op = vm_getbits(command, 54, 3);
196 if(op) {
197 return eval_compare(op, eval_reg(command, vm_getbits(command, 47, 8)),
198 eval_reg_or_data(command, vm_getbits(command, 55, 1), 15));
199 }
200 return 1;
201 }
202
203 /* Evaluate if version 4.
204 Has comparison data in byte 1 and 4-5 (immediate or register)
205 The register in byte 1 is only the lowe nibble (4 bits) */
206 static int32_t eval_if_version_4(command_t* command) {
207 uint8_t op = vm_getbits(command, 54, 3);
208 if(op) {
209 return eval_compare(op, eval_reg(command, vm_getbits(command, 51, 4)),
210 eval_reg_or_data(command, vm_getbits(command, 55, 1), 31));
211 }
212 return 1;
213 }
214
215 /* Evaluate special instruction.... returns the new row/line number,
216 0 if no new row and 256 if Break. */
217 static int32_t eval_special_instruction(command_t* command, int32_t cond) {
218 int32_t line, level;
219
220 switch(vm_getbits(command, 51, 4)) {
221 case 0: /* NOP */
222 line = 0;
223 return cond ? line : 0;
224 case 1: /* Goto line */
225 line = vm_getbits(command, 7, 8);
226 return cond ? line : 0;
227 case 2: /* Break */
228 /* max number of rows < 256, so we will end this set */
229 line = 256;
230 return cond ? 256 : 0;
231 case 3: /* Set temporary parental level and goto */
232 line = vm_getbits(command, 7, 8);
233 level = vm_getbits(command, 11, 4);
234 if(cond) {
235 /* This always succeeds now, if we want real parental protection */
236 /* we need to ask the user and have passwords and stuff. */
237 command->registers->SPRM[13] = level;
238 }
239 return cond ? line : 0;
240 }
241 return 0;
242 }
243
244 /* Evaluate link by subinstruction.
245 Return 1 if link, or 0 if no link
246 Actual link instruction is in return_values parameter */
247 static int32_t eval_link_subins(command_t* command, int32_t cond, link_t *return_values) {
248 uint16_t button = vm_getbits(command, 15, 6);
249 uint8_t linkop = vm_getbits(command, 4, 5);
250
251 if(linkop > 0x10)
252 return 0; /* Unknown Link by Sub-Instruction command */
253
254 /* Assumes that the link_cmd_t enum has the same values as the LinkSIns codes */
255 return_values->command = linkop;
256 return_values->data1 = button;
257 return cond;
258 }
259
260
261 /* Evaluate link instruction.
262 Return 1 if link, or 0 if no link
263 Actual link instruction is in return_values parameter */
264 static int32_t eval_link_instruction(command_t* command, int32_t cond, link_t *return_values) {
265 uint8_t op = vm_getbits(command, 51, 4);
266
267 switch(op) {
268 case 1:
269 return eval_link_subins(command, cond, return_values);
270 case 4:
271 return_values->command = LinkPGCN;
272 return_values->data1 = vm_getbits(command, 14, 15);
273 return cond;
274 case 5:
275 return_values->command = LinkPTTN;
276 return_values->data1 = vm_getbits(command, 9, 10);
277 return_values->data2 = vm_getbits(command, 15, 6);
278 return cond;
279 case 6:
280 return_values->command = LinkPGN;
281 return_values->data1 = vm_getbits(command, 6, 7);
282 return_values->data2 = vm_getbits(command, 15, 6);
283 return cond;
284 case 7:
285 return_values->command = LinkCN;
286 return_values->data1 = vm_getbits(command, 7, 8);
287 return_values->data2 = vm_getbits(command, 15, 6);
288 return cond;
289 }
290 return 0;
291 }
292
293
294 /* Evaluate a jump instruction.
295 returns 1 if jump or 0 if no jump
296 actual jump instruction is in return_values parameter */
297 static int32_t eval_jump_instruction(command_t* command, int32_t cond, link_t *return_values) {
298
299 switch(vm_getbits(command, 51, 4)) {
300 case 1:
301 return_values->command = Exit;
302 return cond;
303 case 2:
304 return_values->command = JumpTT;
305 return_values->data1 = vm_getbits(command, 22, 7);
306 return cond;
307 case 3:
308 return_values->command = JumpVTS_TT;
309 return_values->data1 = vm_getbits(command, 22, 7);
310 return cond;
311 case 5:
312 return_values->command = JumpVTS_PTT;
313 return_values->data1 = vm_getbits(command, 22, 7);
314 return_values->data2 = vm_getbits(command, 41, 10);
315 return cond;
316 case 6:
317 switch(vm_getbits(command, 23, 2)) {
318 case 0:
319 return_values->command = JumpSS_FP;
320 return cond;
321 case 1:
322 return_values->command = JumpSS_VMGM_MENU;
323 return_values->data1 = vm_getbits(command, 19, 4);
324 return cond;
325 case 2:
326 return_values->command = JumpSS_VTSM;
327 return_values->data1 = vm_getbits(command, 31, 8);
328 return_values->data2 = vm_getbits(command, 39, 8);
329 return_values->data3 = vm_getbits(command, 19, 4);
330 return cond;
331 case 3:
332 return_values->command = JumpSS_VMGM_PGC;
333 return_values->data1 = vm_getbits(command, 46, 15);
334 return cond;
335 }
336 break;
337 case 8:
338 switch(vm_getbits(command, 23, 2)) {
339 case 0:
340 return_values->command = CallSS_FP;
341 return_values->data1 = vm_getbits(command, 31, 8);
342 return cond;
343 case 1:
344 return_values->command = CallSS_VMGM_MENU;
345 return_values->data1 = vm_getbits(command, 19, 4);
346 return_values->data2 = vm_getbits(command, 31, 8);
347 return cond;
348 case 2:
349 return_values->command = CallSS_VTSM;
350 return_values->data1 = vm_getbits(command, 19, 4);
351 return_values->data2 = vm_getbits(command, 31, 8);
352 return cond;
353 case 3:
354 return_values->command = CallSS_VMGM_PGC;
355 return_values->data1 = vm_getbits(command, 46, 15);
356 return_values->data2 = vm_getbits(command, 31, 8);
357 return cond;
358 }
359 break;
360 }
361 return 0;
362 }
363
364 /* Evaluate a set sytem register instruction
365 May contain a link so return the same as eval_link */
366 static int32_t eval_system_set(command_t* command, int32_t cond, link_t *return_values) {
367 int32_t i;
368 uint16_t data, data2;
369
370 switch(vm_getbits(command, 59, 4)) {
371 case 1: /* Set system reg 1 &| 2 &| 3 (Audio, Subp. Angle) */
372 for(i = 1; i <= 3; i++) {
373 if(vm_getbits(command, 63 - ((2 + i)*8), 1)) {
374 data = eval_reg_or_data_2(command, vm_getbits(command, 60, 1), (47 - (i*8)));
375 if(cond) {
376 command->registers->SPRM[i] = data;
377 }
378 }
379 }
380 break;
381 case 2: /* Set system reg 9 & 10 (Navigation timer, Title PGC number) */
382 data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 47);
383 data2 = vm_getbits(command, 23, 8); /* ?? size */
384 if(cond) {
385 command->registers->SPRM[9] = data; /* time */
386 command->registers->SPRM[10] = data2; /* pgcN */
387 }
388 break;
389 case 3: /* Mode: Counter / Register + Set */
390 data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 47);
391 data2 = vm_getbits(command, 19, 4);
392 if(vm_getbits(command, 23, 1)) {
393 command->registers->GPRM_mode[data2] |= 1; /* Set bit 0 */
394 } else {
395 command->registers->GPRM_mode[data2] &= ~ 0x01; /* Reset bit 0 */
396 }
397 if(cond) {
398 set_GPRM(command->registers, data2, data);
399 }
400 break;
401 case 6: /* Set system reg 8 (Highlighted button) */
402 data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 31); /* Not system reg!! */
403 if(cond) {
404 command->registers->SPRM[8] = data;
405 }
406 break;
407 }
408 if(vm_getbits(command, 51, 4)) {
409 return eval_link_instruction(command, cond, return_values);
410 }
411 return 0;
412 }
413
414
415 /* Evaluate set operation
416 Sets the register given to the value indicated by op and data.
417 For the swap case the contents of reg is stored in reg2.
418 */
419 static void eval_set_op(command_t* command, int32_t op, int32_t reg, int32_t reg2, int32_t data) {
420 static const int32_t shortmax = 0xffff;
421 int32_t tmp;
422 switch(op) {
423 case 1:
424 set_GPRM(command->registers, reg, data);
425 break;
426 case 2: /* SPECIAL CASE - SWAP! */
427 set_GPRM(command->registers, reg2, get_GPRM(command->registers, reg));
428 set_GPRM(command->registers, reg, data);
429 break;
430 case 3:
431 tmp = get_GPRM(command->registers, reg) + data;
432 if(tmp > shortmax) tmp = shortmax;
433 set_GPRM(command->registers, reg, (uint16_t)tmp);
434 break;
435 case 4:
436 tmp = get_GPRM(command->registers, reg) - data;
437 if(tmp < 0) tmp = 0;
438 set_GPRM(command->registers, reg, (uint16_t)tmp);
439 break;
440 case 5:
441 tmp = get_GPRM(command->registers, reg) * data;
442 if(tmp > shortmax) tmp = shortmax;
443 set_GPRM(command->registers, reg, (uint16_t)tmp);
444 break;
445 case 6:
446 if (data != 0) {
447 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) / data) );
448 } else {
449 set_GPRM(command->registers, reg, 0xffff); /* Avoid that divide by zero! */
450 }
451 break;
452 case 7:
453 if (data != 0) {
454 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) % data) );
455 } else {
456 set_GPRM(command->registers, reg, 0xffff); /* Avoid that divide by zero! */
457 }
458 break;
459 case 8: /* SPECIAL CASE - RND! Return numbers between 1 and data. */
460 set_GPRM(command->registers, reg, 1 + ((uint16_t) ((float) data * rand()/(RAND_MAX+1.0))) );
461 break;
462 case 9:
463 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) & data) );
464 break;
465 case 10:
466 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) | data) );
467 break;
468 case 11:
469 set_GPRM(command->registers, reg, (get_GPRM(command->registers, reg) ^ data) );
470 break;
471 }
472 }
473
474 /* Evaluate set instruction, combined with either Link or Compare. */
475 static void eval_set_version_1(command_t* command, int32_t cond) {
476 uint8_t op = vm_getbits(command, 59, 4);
477 uint8_t reg = vm_getbits(command, 35, 4); /* FIXME: This is different from vmcmd.c!!! */
478 uint8_t reg2 = vm_getbits(command, 19, 4);
479 uint16_t data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 31);
480
481 if(cond) {
482 eval_set_op(command, op, reg, reg2, data);
483 }
484 }
485
486
487 /* Evaluate set instruction, combined with both Link and Compare. */
488 static void eval_set_version_2(command_t* command, int32_t cond) {
489 uint8_t op = vm_getbits(command, 59, 4);
490 uint8_t reg = vm_getbits(command, 51, 4);
491 uint8_t reg2 = vm_getbits(command, 35, 4); /* FIXME: This is different from vmcmd.c!!! */
492 uint16_t data = eval_reg_or_data(command, vm_getbits(command, 60, 1), 47);
493
494 if(cond) {
495 eval_set_op(command, op, reg, reg2, data);
496 }
497 }
498
499
500 /* Evaluate a command
501 returns row number of goto, 0 if no goto, -1 if link.
502 Link command in return_values */
503 static int32_t eval_command(uint8_t *bytes, registers_t* registers, link_t *return_values) {
504 int32_t cond, res = 0;
505 command_t command;
506 command.instruction =( (uint64_t) bytes[0] << 56 ) |
507 ( (uint64_t) bytes[1] << 48 ) |
508 ( (uint64_t) bytes[2] << 40 ) |
509 ( (uint64_t) bytes[3] << 32 ) |
510 ( (uint64_t) bytes[4] << 24 ) |
511 ( (uint64_t) bytes[5] << 16 ) |
512 ( (uint64_t) bytes[6] << 8 ) |
513 (uint64_t) bytes[7] ;
514 command.examined = 0;
515 command.registers = registers;
516 memset(return_values, 0, sizeof(link_t));
517
518 switch(vm_getbits(&command, 63, 3)) { /* three first old_bits */
519 case 0: /* Special instructions */
520 cond = eval_if_version_1(&command);
521 res = eval_special_instruction(&command, cond);
522 if(res == -1) {
523 fprintf(MSG_OUT, "libdvdnav: Unknown Instruction!\n");
524 abort();
525 }
526 break;
527 case 1: /* Link/jump instructions */
528 if(vm_getbits(&command, 60, 1)) {
529 cond = eval_if_version_2(&command);
530 res = eval_jump_instruction(&command, cond, return_values);
531 } else {
532 cond = eval_if_version_1(&command);
533 res = eval_link_instruction(&command, cond, return_values);
534 }
535 if(res)
536 res = -1;
537 break;
538 case 2: /* System set instructions */
539 cond = eval_if_version_2(&command);
540 res = eval_system_set(&command, cond, return_values);
541 if(res)
542 res = -1;
543 break;
544 case 3: /* Set instructions, either Compare or Link may be used */
545 cond = eval_if_version_3(&command);
546 eval_set_version_1(&command, cond);
547 if(vm_getbits(&command, 51, 4)) {
548 res = eval_link_instruction(&command, cond, return_values);
549 }
550 if(res)
551 res = -1;
552 break;
553 case 4: /* Set, Compare -> Link Sub-Instruction */
554 eval_set_version_2(&command, /*True*/ 1);
555 cond = eval_if_version_4(&command);
556 res = eval_link_subins(&command, cond, return_values);
557 if(res)
558 res = -1;
559 break;
560 case 5: /* Compare -> (Set and Link Sub-Instruction) */
561 /* FIXME: These are wrong. Need to be updated from vmcmd.c */
562 cond = eval_if_version_4(&command);
563 eval_set_version_2(&command, cond);
564 res = eval_link_subins(&command, cond, return_values);
565 if(res)
566 res = -1;
567 break;
568 case 6: /* Compare -> Set, allways Link Sub-Instruction */
569 /* FIXME: These are wrong. Need to be updated from vmcmd.c */
570 cond = eval_if_version_4(&command);
571 eval_set_version_2(&command, cond);
572 res = eval_link_subins(&command, /*True*/ 1, return_values);
573 if(res)
574 res = -1;
575 break;
576 default: /* Unknown command */
577 fprintf(MSG_OUT, "libdvdnav: WARNING: Unknown Command=%x\n", vm_getbits(&command, 63, 3));
578 abort();
579 }
580 /* Check if there are bits not yet examined */
581
582 if(command.instruction & ~ command.examined) {
583 fprintf(MSG_OUT, "libdvdnav: decoder.c: [WARNING, unknown bits:");
584 fprintf(MSG_OUT, " %08"PRIx64, (command.instruction & ~ command.examined) );
585 fprintf(MSG_OUT, "]\n");
586 }
587
588 return res;
589 }
590
591 /* Evaluate a set of commands in the given register set (which is modified) */
592 int32_t vmEval_CMD(vm_cmd_t commands[], int32_t num_commands,
593 registers_t *registers, link_t *return_values) {
594 int32_t i = 0;
595 int32_t total = 0;
596
597 #ifdef TRACE
598 /* DEBUG */
599 fprintf(MSG_OUT, "libdvdnav: Registers before transaction\n");
600 vm_print_registers( registers );
601 fprintf(MSG_OUT, "libdvdnav: Full list of commands to execute\n");
602 for(i = 0; i < num_commands; i++)
603 vm_print_cmd(i, &commands[i]);
604 fprintf(MSG_OUT, "libdvdnav: --------------------------------------------\n");
605 fprintf(MSG_OUT, "libdvdnav: Single stepping commands\n");
606 #endif
607
608 i = 0;
609 while(i < num_commands && total < 100000) {
610 int32_t line;
611
612 #ifdef TRACE
613 vm_print_cmd(i, &commands[i]);
614 #endif
615
616 line = eval_command(&commands[i].bytes[0], registers, return_values);
617
618 if (line < 0) { /* Link command */
619 #ifdef TRACE
620 fprintf(MSG_OUT, "libdvdnav: Registers after transaction\n");
621 vm_print_registers( registers );
622 fprintf(MSG_OUT, "libdvdnav: eval: Doing Link/Jump/Call\n");
623 #endif
624 return 1;
625 }
626
627 if (line > 0) /* Goto command */
628 i = line - 1;
629 else /* Just continue on the next line */
630 i++;
631
632 total++;
633 }
634
635 memset(return_values, 0, sizeof(link_t));
636 #ifdef TRACE
637 fprintf(MSG_OUT, "libdvdnav: Registers after transaction\n");
638 vm_print_registers( registers );
639 #endif
640 return 0;
641 }
642
643 #ifdef TRACE
644
645 static char *linkcmd2str(link_cmd_t cmd) {
646 switch(cmd) {
647 case LinkNoLink:
648 return "LinkNoLink";
649 case LinkTopC:
650 return "LinkTopC";
651 case LinkNextC:
652 return "LinkNextC";
653 case LinkPrevC:
654 return "LinkPrevC";
655 case LinkTopPG:
656 return "LinkTopPG";
657 case LinkNextPG:
658 return "LinkNextPG";
659 case LinkPrevPG:
660 return "LinkPrevPG";
661 case LinkTopPGC:
662 return "LinkTopPGC";
663 case LinkNextPGC:
664 return "LinkNextPGC";
665 case LinkPrevPGC:
666 return "LinkPrevPGC";
667 case LinkGoUpPGC:
668 return "LinkGoUpPGC";
669 case LinkTailPGC:
670 return "LinkTailPGC";
671 case LinkRSM:
672 return "LinkRSM";
673 case LinkPGCN:
674 return "LinkPGCN";
675 case LinkPTTN:
676 return "LinkPTTN";
677 case LinkPGN:
678 return "LinkPGN";
679 case LinkCN:
680 return "LinkCN";
681 case Exit:
682 return "Exit";
683 case JumpTT:
684 return "JumpTT";
685 case JumpVTS_TT:
686 return "JumpVTS_TT";
687 case JumpVTS_PTT:
688 return "JumpVTS_PTT";
689 case JumpSS_FP:
690 return "JumpSS_FP";
691 case JumpSS_VMGM_MENU:
692 return "JumpSS_VMGM_MENU";
693 case JumpSS_VTSM:
694 return "JumpSS_VTSM";
695 case JumpSS_VMGM_PGC:
696 return "JumpSS_VMGM_PGC";
697 case CallSS_FP:
698 return "CallSS_FP";
699 case CallSS_VMGM_MENU:
700 return "CallSS_VMGM_MENU";
701 case CallSS_VTSM:
702 return "CallSS_VTSM";
703 case CallSS_VMGM_PGC:
704 return "CallSS_VMGM_PGC";
705 case PlayThis:
706 return "PlayThis";
707 }
708 return "*** (bug)";
709 }
710
711 void vm_print_link(link_t value) {
712 char *cmd = linkcmd2str(value.command);
713
714 switch(value.command) {
715 case LinkNoLink:
716 case LinkTopC:
717 case LinkNextC:
718 case LinkPrevC:
719 case LinkTopPG:
720 case LinkNextPG:
721 case LinkPrevPG:
722 case LinkTopPGC:
723 case LinkNextPGC:
724 case LinkPrevPGC:
725 case LinkGoUpPGC:
726 case LinkTailPGC:
727 case LinkRSM:
728 fprintf(MSG_OUT, "libdvdnav: %s (button %d)\n", cmd, value.data1);
729 break;
730 case LinkPGCN:
731 case JumpTT:
732 case JumpVTS_TT:
733 case JumpSS_VMGM_MENU: /* == 2 -> Title Menu */
734 case JumpSS_VMGM_PGC:
735 fprintf(MSG_OUT, "libdvdnav: %s %d\n", cmd, value.data1);
736 break;
737 case LinkPTTN:
738 case LinkPGN:
739 case LinkCN:
740 fprintf(MSG_OUT, "libdvdnav: %s %d (button %d)\n", cmd, value.data1, value.data2);
741 break;
742 case Exit:
743 case JumpSS_FP:
744 case PlayThis: /* Humm.. should we have this at all.. */
745 fprintf(MSG_OUT, "libdvdnav: %s\n", cmd);
746 break;
747 case JumpVTS_PTT:
748 fprintf(MSG_OUT, "libdvdnav: %s %d:%d\n", cmd, value.data1, value.data2);
749 break;
750 case JumpSS_VTSM:
751 fprintf(MSG_OUT, "libdvdnav: %s vts %d title %d menu %d\n",
752 cmd, value.data1, value.data2, value.data3);
753 break;
754 case CallSS_FP:
755 fprintf(MSG_OUT, "libdvdnav: %s resume cell %d\n", cmd, value.data1);
756 break;
757 case CallSS_VMGM_MENU: /* == 2 -> Title Menu */
758 case CallSS_VTSM:
759 fprintf(MSG_OUT, "libdvdnav: %s %d resume cell %d\n", cmd, value.data1, value.data2);
760 break;
761 case CallSS_VMGM_PGC:
762 fprintf(MSG_OUT, "libdvdnav: %s %d resume cell %d\n", cmd, value.data1, value.data2);
763 break;
764 }
765 }
766
767 void vm_print_registers( registers_t *registers ) {
768 int32_t i;
769 fprintf(MSG_OUT, "libdvdnav: # ");
770 for(i = 0; i < 24; i++)
771 fprintf(MSG_OUT, " %2d |", i);
772 fprintf(MSG_OUT, "\nlibdvdnav: SRPMS: ");
773 for(i = 0; i < 24; i++)
774 fprintf(MSG_OUT, "%04x|", registers->SPRM[i]);
775 fprintf(MSG_OUT, "\nlibdvdnav: GRPMS: ");
776 for(i = 0; i < 16; i++)
777 fprintf(MSG_OUT, "%04x|", get_GPRM(registers, i) );
778 fprintf(MSG_OUT, "\nlibdvdnav: Gmode: ");
779 for(i = 0; i < 16; i++)
780 fprintf(MSG_OUT, "%04x|", registers->GPRM_mode[i]);
781 fprintf(MSG_OUT, "\nlibdvdnav: Gtime: ");
782 for(i = 0; i < 16; i++)
783 fprintf(MSG_OUT, "%04lx|", registers->GPRM_time[i].tv_sec & 0xffff);
784 fprintf(MSG_OUT, "\n");
785 }
786
787 #endif
788