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