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