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