Mercurial > libdvdnav.hg
annotate vm/vmcmd.c @ 257:0340d2236219 src
newer versions of libtool claim the LT_* namespace for themselves, so
we name the LT_* variables to DVDNAV_LT_*
author | mroi |
---|---|
date | Mon, 03 Jan 2005 20:24:21 +0000 |
parents | e75c52894630 |
children | 130c10495b66 |
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 <ctype.h> | |
32 #include <inttypes.h> | |
33 | |
34 #include "dvdnav_internal.h" | |
35 | |
36 /* freebsd compatibility */ | |
37 #ifndef PRIu8 | |
38 #define PRIu8 "d" | |
39 #endif | |
40 | |
41 /* freebsd compatibility */ | |
42 #ifndef PRIu16 | |
43 #define PRIu16 "d" | |
44 #endif | |
45 | |
46 static const char *cmp_op_table[] = { | |
47 NULL, "&", "==", "!=", ">=", ">", "<=", "<" | |
48 }; | |
49 static const char *set_op_table[] = { | |
50 NULL, "=", "<->", "+=", "-=", "*=", "/=", "%=", "rnd", "&=", "|=", "^=" | |
51 }; | |
52 | |
53 static const char *link_table[] = { | |
54 "LinkNoLink", "LinkTopC", "LinkNextC", "LinkPrevC", | |
55 NULL, "LinkTopPG", "LinkNextPG", "LinkPrevPG", | |
56 NULL, "LinkTopPGC", "LinkNextPGC", "LinkPrevPGC", | |
57 "LinkGoUpPGC", "LinkTailPGC", NULL, NULL, | |
58 "RSM" | |
59 }; | |
60 | |
61 static const char *system_reg_table[] = { | |
62 "Menu Description Language Code", | |
63 "Audio Stream Number", | |
64 "Sub-picture Stream Number", | |
65 "Angle Number", | |
66 "Title Track Number", | |
67 "VTS Title Track Number", | |
68 "VTS PGC Number", | |
69 "PTT Number for One_Sequential_PGC_Title", | |
70 "Highlighted Button Number", | |
71 "Navigation Timer", | |
72 "Title PGC Number for Navigation Timer", | |
73 "Audio Mixing Mode for Karaoke", | |
74 "Country Code for Parental Management", | |
75 "Parental Level", | |
76 "Player Configurations for Video", | |
77 "Player Configurations for Audio", | |
78 "Initial Language Code for Audio", | |
79 "Initial Language Code Extension for Audio", | |
80 "Initial Language Code for Sub-picture", | |
81 "Initial Language Code Extension for Sub-picture", | |
82 "Player Regional Code", | |
83 "Reserved 21", | |
84 "Reserved 22", | |
85 "Reserved 23" | |
86 }; | |
87 | |
88 static const char *system_reg_abbr_table[] = { | |
89 NULL, | |
90 "ASTN", | |
91 "SPSTN", | |
92 "AGLN", | |
93 "TTN", | |
94 "VTS_TTN", | |
95 "TT_PGCN", | |
96 "PTTN", | |
97 "HL_BTNN", | |
98 "NVTMR", | |
99 "NV_PGCN", | |
100 NULL, | |
101 "CC_PLT", | |
102 "PLT", | |
103 NULL, | |
104 NULL, | |
105 NULL, | |
106 NULL, | |
107 NULL, | |
108 NULL, | |
109 NULL, | |
110 NULL, | |
111 NULL, | |
112 NULL, | |
113 }; | |
114 | |
115 static void print_system_reg(uint16_t reg) { | |
116 if(reg < sizeof(system_reg_abbr_table) / sizeof(char *)) | |
117 fprintf(MSG_OUT, "%s (SRPM:%d)", system_reg_table[reg], reg); | |
118 else | |
119 fprintf(MSG_OUT, " WARNING: Unknown system register ( reg=%d ) ", reg); | |
120 } | |
121 | |
122 static void print_g_reg(uint8_t reg) { | |
123 if(reg < 16) | |
124 fprintf(MSG_OUT, "g[%" PRIu8 "]", reg); | |
125 else | |
126 fprintf(MSG_OUT, " WARNING: Unknown general register "); | |
127 } | |
128 | |
129 static void print_reg(uint8_t reg) { | |
130 if(reg & 0x80) | |
131 print_system_reg(reg & 0x7f); | |
132 else | |
133 print_g_reg(reg & 0x7f); | |
134 } | |
135 | |
136 static void print_cmp_op(uint8_t op) { | |
137 if(op < sizeof(cmp_op_table) / sizeof(char *) && cmp_op_table[op] != NULL) | |
138 fprintf(MSG_OUT, " %s ", cmp_op_table[op]); | |
139 else | |
140 fprintf(MSG_OUT, " WARNING: Unknown compare op "); | |
141 } | |
142 | |
143 static void print_set_op(uint8_t op) { | |
144 if(op < sizeof(set_op_table) / sizeof(char *) && set_op_table[op] != NULL) | |
145 fprintf(MSG_OUT, " %s ", set_op_table[op]); | |
146 else | |
147 fprintf(MSG_OUT, " WARNING: Unknown set op "); | |
148 } | |
149 | |
150 static void print_reg_or_data(command_t* command, int immediate, int start) { | |
151 if(immediate) { | |
152 uint32_t i = vm_getbits(command, start, 16); | |
153 | |
154 fprintf(MSG_OUT, "0x%x", i); | |
155 if(isprint(i & 0xff) && isprint((i>>8) & 0xff)) | |
156 fprintf(MSG_OUT, " (\"%c%c\")", (char)((i>>8) & 0xff), (char)(i & 0xff)); | |
157 } else { | |
158 print_reg(vm_getbits(command, start - 8, 8)); | |
159 } | |
160 } | |
161 | |
162 static void print_reg_or_data_2(command_t* command, int immediate, int start) { | |
163 if(immediate) | |
164 fprintf(MSG_OUT, "0x%x", vm_getbits(command, start - 1, 7)); | |
165 else | |
166 fprintf(MSG_OUT, "g[%" PRIu8 "]", vm_getbits(command, start - 4, 4)); | |
167 } | |
168 | |
169 static void print_reg_or_data_3(command_t* command, int immediate, int start) { | |
170 if(immediate) { | |
171 uint32_t i = vm_getbits(command, start, 16); | |
172 | |
173 fprintf(MSG_OUT, "0x%x", i); | |
174 if(isprint(i & 0xff) && isprint((i>>8) & 0xff)) | |
175 fprintf(MSG_OUT, " (\"%c%c\")", (char)((i>>8) & 0xff), (char)(i & 0xff)); | |
176 } else { | |
177 print_reg(vm_getbits(command, start, 8)); | |
178 } | |
179 } | |
180 | |
181 | |
182 static void print_if_version_1(command_t* command) { | |
183 uint8_t op = vm_getbits(command, 54, 3); | |
184 | |
185 if(op) { | |
186 fprintf(MSG_OUT, "if ("); | |
187 print_g_reg(vm_getbits(command,39,8)); | |
188 print_cmp_op(op); | |
189 print_reg_or_data(command, vm_getbits(command, 55,1), 31); | |
190 fprintf(MSG_OUT, ") "); | |
191 } | |
192 } | |
193 | |
194 static void print_if_version_2(command_t* command) { | |
195 uint8_t op = vm_getbits(command, 54, 3); | |
196 | |
197 if(op) { | |
198 fprintf(MSG_OUT, "if ("); | |
199 print_reg(vm_getbits(command, 15, 8)); | |
200 print_cmp_op(op); | |
201 print_reg(vm_getbits(command, 7, 8)); | |
202 fprintf(MSG_OUT, ") "); | |
203 } | |
204 } | |
205 | |
206 static void print_if_version_3(command_t* command) { | |
207 uint8_t op = vm_getbits(command, 54, 3); | |
208 | |
209 if(op) { | |
210 fprintf(MSG_OUT, "if ("); | |
211 print_g_reg(vm_getbits(command, 43, 4)); | |
212 print_cmp_op(op); | |
213 print_reg_or_data(command, vm_getbits(command, 55, 1), 15); | |
214 fprintf(MSG_OUT, ") "); | |
215 } | |
216 } | |
217 | |
218 static void print_if_version_4(command_t* command) { | |
219 uint8_t op = vm_getbits(command, 54, 3); | |
220 | |
221 if(op) { | |
222 fprintf(MSG_OUT, "if ("); | |
223 print_g_reg(vm_getbits(command, 51, 4)); | |
224 print_cmp_op(op); | |
225 print_reg_or_data(command, vm_getbits(command, 55, 1), 31); | |
226 fprintf(MSG_OUT, ") "); | |
227 } | |
228 } | |
229 | |
230 static void print_if_version_5(command_t* command) { | |
231 uint8_t op = vm_getbits(command, 54, 3); | |
232 int set_immediate = vm_getbits(command, 60, 1); | |
233 | |
234 if(op) { | |
235 if (set_immediate) { | |
236 fprintf(MSG_OUT, "if ("); | |
237 print_g_reg(vm_getbits(command, 31, 8)); | |
238 print_cmp_op(op); | |
239 print_reg(vm_getbits(command, 23, 8)); | |
240 fprintf(MSG_OUT, ") "); | |
241 } else { | |
242 fprintf(MSG_OUT, "if ("); | |
243 print_g_reg(vm_getbits(command, 39, 8)); | |
244 print_cmp_op(op); | |
245 print_reg_or_data(command, vm_getbits(command, 55, 1), 31); | |
246 fprintf(MSG_OUT, ") "); | |
247 } | |
248 } | |
249 } | |
250 | |
251 static void print_special_instruction(command_t* command) { | |
252 uint8_t op = vm_getbits(command, 51, 4); | |
253 | |
254 switch(op) { | |
255 case 0: /* NOP */ | |
256 fprintf(MSG_OUT, "Nop"); | |
257 break; | |
258 case 1: /* Goto line */ | |
259 fprintf(MSG_OUT, "Goto %" PRIu8, vm_getbits(command, 7, 8)); | |
260 break; | |
261 case 2: /* Break */ | |
262 fprintf(MSG_OUT, "Break"); | |
263 break; | |
264 case 3: /* Parental level */ | |
265 fprintf(MSG_OUT, "SetTmpPML %" PRIu8 ", Goto %" PRIu8, | |
266 vm_getbits(command, 11, 4), vm_getbits(command, 7, 8)); | |
267 break; | |
268 default: | |
269 fprintf(MSG_OUT, "WARNING: Unknown special instruction (%i)", | |
270 vm_getbits(command, 51, 4)); | |
271 } | |
272 } | |
273 | |
274 static void print_linksub_instruction(command_t* command) { | |
275 uint32_t linkop = vm_getbits(command, 7, 8); | |
276 uint32_t button = vm_getbits(command, 15, 6); | |
277 | |
278 if(linkop < sizeof(link_table)/sizeof(char *) && link_table[linkop] != NULL) | |
279 fprintf(MSG_OUT, "%s (button %" PRIu8 ")", link_table[linkop], button); | |
280 else | |
281 fprintf(MSG_OUT, "WARNING: Unknown linksub instruction (%i)", linkop); | |
282 } | |
283 | |
284 static void print_link_instruction(command_t* command, int optional) { | |
285 uint8_t op = vm_getbits(command, 51, 4); | |
286 | |
287 if(optional && op) | |
288 fprintf(MSG_OUT, ", "); | |
289 | |
290 switch(op) { | |
291 case 0: | |
292 if(!optional) | |
293 fprintf(MSG_OUT, "WARNING: NOP (link)!"); | |
294 break; | |
295 case 1: | |
296 print_linksub_instruction(command); | |
297 break; | |
298 case 4: | |
299 fprintf(MSG_OUT, "LinkPGCN %" PRIu16, vm_getbits(command, 14, 15)); | |
300 break; | |
301 case 5: | |
302 fprintf(MSG_OUT, "LinkPTT %" PRIu16 " (button %" PRIu8 ")", | |
303 vm_getbits(command, 9, 10), vm_getbits(command, 15, 6)); | |
304 break; | |
305 case 6: | |
306 fprintf(MSG_OUT, "LinkPGN %" PRIu8 " (button %" PRIu8 ")", | |
307 vm_getbits(command, 6, 7), vm_getbits(command, 15, 6)); | |
308 break; | |
309 case 7: | |
310 fprintf(MSG_OUT, "LinkCN %" PRIu8 " (button %" PRIu8 ")", | |
311 vm_getbits(command, 7, 8), vm_getbits(command, 15, 6)); | |
312 break; | |
313 default: | |
314 fprintf(MSG_OUT, "WARNING: Unknown link instruction"); | |
315 } | |
316 } | |
317 | |
318 static void print_jump_instruction(command_t* command) { | |
319 switch(vm_getbits(command, 51, 4)) { | |
320 case 1: | |
321 fprintf(MSG_OUT, "Exit"); | |
322 break; | |
323 case 2: | |
324 fprintf(MSG_OUT, "JumpTT %" PRIu8, vm_getbits(command, 22, 7)); | |
325 break; | |
326 case 3: | |
327 fprintf(MSG_OUT, "JumpVTS_TT %" PRIu8, vm_getbits(command, 22, 7)); | |
328 break; | |
329 case 5: | |
330 fprintf(MSG_OUT, "JumpVTS_PTT %" PRIu8 ":%" PRIu16, | |
331 vm_getbits(command, 22, 7), vm_getbits(command, 41, 10)); | |
332 break; | |
333 case 6: | |
334 switch(vm_getbits(command, 23, 2)) { | |
335 case 0: | |
336 fprintf(MSG_OUT, "JumpSS FP"); | |
337 break; | |
338 case 1: | |
339 fprintf(MSG_OUT, "JumpSS VMGM (menu %" PRIu8 ")", vm_getbits(command, 19, 4)); | |
340 break; | |
341 case 2: | |
342 fprintf(MSG_OUT, "JumpSS VTSM (vts %" PRIu8 ", title %" PRIu8 | |
343 ", menu %" PRIu8 ")", vm_getbits(command, 30, 7), vm_getbits(command, 38, 7), vm_getbits(command, 19, 4)); | |
344 break; | |
345 case 3: | |
346 fprintf(MSG_OUT, "JumpSS VMGM (pgc %" PRIu8 ")", vm_getbits(command, 46, 15)); | |
347 break; | |
348 } | |
349 break; | |
350 case 8: | |
351 switch(vm_getbits(command, 23, 2)) { | |
352 case 0: | |
353 fprintf(MSG_OUT, "CallSS FP (rsm_cell %" PRIu8 ")", | |
354 vm_getbits(command, 31, 8)); | |
355 break; | |
356 case 1: | |
357 fprintf(MSG_OUT, "CallSS VMGM (menu %" PRIu8 | |
358 ", rsm_cell %" PRIu8 ")", vm_getbits(command, 19, 4), vm_getbits(command, 31, 8)); | |
359 break; | |
360 case 2: | |
361 fprintf(MSG_OUT, "CallSS VTSM (menu %" PRIu8 | |
362 ", rsm_cell %" PRIu8 ")", vm_getbits(command, 19, 4), vm_getbits(command, 31, 8)); | |
363 break; | |
364 case 3: | |
365 fprintf(MSG_OUT, "CallSS VMGM (pgc %" PRIu8 ", rsm_cell %" PRIu8 ")", | |
366 vm_getbits(command, 46, 15), vm_getbits(command, 31, 8)); | |
367 break; | |
368 } | |
369 break; | |
370 default: | |
371 fprintf(MSG_OUT, "WARNING: Unknown Jump/Call instruction"); | |
372 } | |
373 } | |
374 | |
375 static void print_system_set(command_t* command) { | |
376 int i; | |
377 /* FIXME: What about SPRM11 ? Karaoke */ | |
378 /* Surely there must be some system set command for that ? */ | |
379 | |
380 switch(vm_getbits(command, 59, 4)) { | |
381 case 1: /* Set system reg 1 &| 2 &| 3 (Audio, Subp. Angle) */ | |
382 for(i = 1; i <= 3; i++) { | |
383 if(vm_getbits(command, 47 - (i*8), 1)) { | |
384 print_system_reg(i); | |
385 fprintf(MSG_OUT, " = "); | |
386 print_reg_or_data_2(command, vm_getbits(command, 60, 1), 47 - (i*8) ); | |
387 fprintf(MSG_OUT, " "); | |
388 } | |
389 } | |
390 break; | |
391 case 2: /* Set system reg 9 & 10 (Navigation timer, Title PGC number) */ | |
392 print_system_reg(9); | |
393 fprintf(MSG_OUT, " = "); | |
394 print_reg_or_data(command, vm_getbits(command, 60, 1), 47); | |
395 fprintf(MSG_OUT, " "); | |
396 print_system_reg(10); | |
397 fprintf(MSG_OUT, " = %" PRIu16, vm_getbits(command, 30, 15)); /* ?? */ | |
398 break; | |
399 case 3: /* Mode: Counter / Register + Set */ | |
400 fprintf(MSG_OUT, "SetMode "); | |
401 if(vm_getbits(command, 23, 1)) | |
402 fprintf(MSG_OUT, "Counter "); | |
403 else | |
404 fprintf(MSG_OUT, "Register "); | |
405 print_g_reg(vm_getbits(command, 19, 4)); | |
406 print_set_op(0x1); /* '=' */ | |
407 print_reg_or_data(command, vm_getbits(command, 60, 1), 47); | |
408 break; | |
409 case 6: /* Set system reg 8 (Highlighted button) */ | |
410 print_system_reg(8); | |
411 if(vm_getbits(command, 60, 1)) /* immediate */ | |
412 fprintf(MSG_OUT, " = 0x%x (button no %d)", vm_getbits(command, 31, 16), vm_getbits(command, 31, 6)); | |
413 else | |
414 fprintf(MSG_OUT, " = g[%" PRIu8 "]", vm_getbits(command, 19, 4)); | |
415 break; | |
416 default: | |
417 fprintf(MSG_OUT, "WARNING: Unknown system set instruction (%i)", | |
418 vm_getbits(command, 59, 4)); | |
419 } | |
420 } | |
421 | |
422 static void print_set_version_1(command_t* command) { | |
423 uint8_t set_op = vm_getbits(command, 59, 4); | |
424 | |
425 if(set_op) { | |
426 print_g_reg(vm_getbits(command, 35, 4)); | |
427 print_set_op(set_op); | |
428 print_reg_or_data(command, vm_getbits(command, 60, 1), 31); | |
429 } else { | |
430 fprintf(MSG_OUT, "NOP"); | |
431 } | |
432 } | |
433 | |
434 static void print_set_version_2(command_t* command) { | |
435 uint8_t set_op = vm_getbits(command, 59, 4); | |
436 | |
437 if(set_op) { | |
438 print_g_reg(vm_getbits(command, 51, 4)); | |
439 print_set_op(set_op); | |
440 print_reg_or_data(command, vm_getbits(command, 60, 1), 47); | |
441 } else { | |
442 fprintf(MSG_OUT, "NOP"); | |
443 } | |
444 } | |
445 | |
446 static void print_set_version_3(command_t* command) { | |
447 uint8_t set_op = vm_getbits(command, 59, 4); | |
448 | |
449 if(set_op) { | |
450 print_g_reg(vm_getbits(command, 51, 4)); | |
451 print_set_op(set_op); | |
452 print_reg_or_data_3(command, vm_getbits(command, 60, 1), 47); | |
453 } else { | |
454 fprintf(MSG_OUT, "NOP"); | |
455 } | |
456 } | |
457 | |
458 | |
459 void vm_print_mnemonic(vm_cmd_t *vm_command) { | |
460 command_t command; | |
461 command.instruction =( (uint64_t) vm_command->bytes[0] << 56 ) | | |
462 ( (uint64_t) vm_command->bytes[1] << 48 ) | | |
463 ( (uint64_t) vm_command->bytes[2] << 40 ) | | |
464 ( (uint64_t) vm_command->bytes[3] << 32 ) | | |
465 ( (uint64_t) vm_command->bytes[4] << 24 ) | | |
466 ( (uint64_t) vm_command->bytes[5] << 16 ) | | |
467 ( (uint64_t) vm_command->bytes[6] << 8 ) | | |
468 (uint64_t) vm_command->bytes[7] ; | |
469 command.examined = 0; | |
470 | |
471 switch(vm_getbits(&command,63,3)) { /* three first bits */ | |
472 case 0: /* Special instructions */ | |
473 print_if_version_1(&command); | |
474 print_special_instruction(&command); | |
475 break; | |
476 case 1: /* Jump/Call or Link instructions */ | |
477 if(vm_getbits(&command,60,1)) { | |
478 print_if_version_2(&command); | |
479 print_jump_instruction(&command); | |
480 } else { | |
481 print_if_version_1(&command); | |
482 print_link_instruction(&command, 0); /* must be pressent */ | |
483 } | |
484 break; | |
485 case 2: /* Set System Parameters instructions */ | |
486 print_if_version_2(&command); | |
487 print_system_set(&command); | |
488 print_link_instruction(&command, 1); /* either 'if' or 'link' */ | |
489 break; | |
490 case 3: /* Set General Parameters instructions */ | |
491 print_if_version_3(&command); | |
492 print_set_version_1(&command); | |
493 print_link_instruction(&command, 1); /* either 'if' or 'link' */ | |
494 break; | |
495 case 4: /* Set, Compare -> LinkSub instructions */ | |
496 print_set_version_2(&command); | |
497 fprintf(MSG_OUT, ", "); | |
498 print_if_version_4(&command); | |
499 print_linksub_instruction(&command); | |
500 break; | |
501 case 5: /* Compare -> (Set and LinkSub) instructions */ | |
502 print_if_version_5(&command); | |
503 fprintf(MSG_OUT, "{ "); | |
504 print_set_version_3(&command); | |
505 fprintf(MSG_OUT, ", "); | |
506 print_linksub_instruction(&command); | |
507 fprintf(MSG_OUT, " }"); | |
508 break; | |
509 case 6: /* Compare -> Set, always LinkSub instructions */ | |
510 print_if_version_5(&command); | |
511 fprintf(MSG_OUT, "{ "); | |
512 print_set_version_3(&command); | |
513 fprintf(MSG_OUT, " } "); | |
514 print_linksub_instruction(&command); | |
515 break; | |
516 default: | |
517 fprintf(MSG_OUT, "WARNING: Unknown instruction type (%i)", vm_getbits(&command, 63, 3)); | |
518 } | |
519 /* Check if there still are bits set that were not examined */ | |
520 | |
521 if(command.instruction & ~ command.examined) { | |
522 fprintf(MSG_OUT, " libdvdnav: vmcmd.c: [WARNING, unknown bits:"); | |
523 fprintf(MSG_OUT, " %08llx", (command.instruction & ~ command.examined) ); | |
524 fprintf(MSG_OUT, "]"); | |
525 } | |
526 } | |
527 | |
528 void vm_print_cmd(int row, vm_cmd_t *vm_command) { | |
529 int i; | |
530 | |
531 fprintf(MSG_OUT, "(%03d) ", row + 1); | |
532 for(i = 0; i < 8; i++) | |
533 fprintf(MSG_OUT, "%02x ", vm_command->bytes[i]); | |
534 fprintf(MSG_OUT, "| "); | |
535 | |
536 vm_print_mnemonic(vm_command); | |
537 fprintf(MSG_OUT, "\n"); | |
538 } | |
539 |