Mercurial > libdvdnav.hg
annotate decoder.c @ 12:1a214a94a80d src
Removed some static variables from decoder.c
Some updates from ogle for register calculations.
Initial work towards working counters.
| author | jcdutton |
|---|---|
| date | Tue, 09 Apr 2002 23:32:45 +0000 |
| parents | 6f0fb88d1463 |
| children | de00f8362634 |
| 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 | |
| 12 | 38 /* Fix theses two.. pass as parameters instead. */ |
| 39 static registers_t *state; | |
| 0 | 40 |
| 41 typedef struct | |
| 42 { | |
| 12 | 43 uint64_t instruction; |
| 44 uint64_t examined; | |
| 45 } command_t; | |
| 46 | |
| 47 static uint32_t new_bits(command_t* command, int32_t start, int32_t count); | |
| 0 | 48 |
| 12 | 49 static uint32_t new_bits(command_t *command, int32_t start, int32_t count) { |
| 50 uint64_t result = 0; | |
| 51 uint64_t bit_mask=0xffffffffffffffff; /* I could put -1 instead */ | |
| 52 uint64_t examining = 0; | |
| 53 if (count == 0) return 0; | |
| 0 | 54 |
| 12 | 55 if ( ((count+start) > 64) || |
| 56 (count > 32) || | |
| 57 (start > 63) || | |
| 58 (count < 0) || | |
| 59 (start < 0) ){ | |
| 60 fprintf(stderr, "Bad call to new_bits. Parameter out of range\n"); | |
| 61 assert(0); | |
| 0 | 62 } |
| 12 | 63 bit_mask >>= start; |
| 64 examining = ((bit_mask >> (64-count-start)) << (64-count-start) ); | |
| 65 command->examined |= examining; | |
| 66 result = (command->instruction & bit_mask) >> (64-count-start); | |
| 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. */ | |
| 72 static uint16_t eval_reg(uint8_t reg) { | |
| 73 if(reg & 0x80) { | |
| 74 return state->SPRM[reg & 0x1f]; /* FIXME max 24 not 32 */ | |
| 75 } else { | |
| 76 return state->GPRM[reg & 0x0f]; | |
| 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 { |
| 12 | 87 return eval_reg(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 |
| 12 | 99 return state->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) { |
| 12 | 132 return eval_compare(op, eval_reg(new_bits(command, 24, 8)), |
| 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) { |
| 12 | 143 return eval_compare(op, eval_reg(new_bits(command, 48, 8)), |
| 144 eval_reg(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) { |
| 12 | 154 return eval_compare(op, eval_reg(new_bits(command, 16, 8)), |
| 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) { |
| 12 | 166 return eval_compare(op, eval_reg(new_bits(command, 12, 4)), |
| 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. */ | |
| 194 state->SPRM[13] = level; | |
| 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) { |
| 333 state->SPRM[i] = data; | |
| 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) { |
| 342 state->SPRM[9] = data; /* time */ | |
| 343 state->SPRM[10] = data2; /* pgcN */ | |
| 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"); |
|
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
351 state->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"); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
354 state->GPRM_mode[data2] = 0; |
| 0 | 355 } |
| 356 if(cond) { | |
| 357 state->GPRM[data2] = data; | |
| 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) { |
| 363 state->SPRM[8] = data; | |
| 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 */ | |
| 12 | 378 static void eval_set_op(int32_t op, int32_t reg, int32_t reg2, int32_t data) { |
| 379 const int32_t shortmax = 0xffff; | |
| 380 int32_t tmp; | |
| 0 | 381 switch(op) { |
| 382 case 1: | |
| 383 state->GPRM[reg] = data; | |
| 384 break; | |
| 385 case 2: /* SPECIAL CASE - SWAP! */ | |
| 386 state->GPRM[reg2] = state->GPRM[reg]; | |
| 387 state->GPRM[reg] = data; | |
| 388 break; | |
| 389 case 3: | |
| 12 | 390 tmp = state->GPRM[reg] + data; |
| 391 if(tmp > shortmax) tmp = shortmax; | |
| 392 state->GPRM[reg] = (uint16_t)tmp; | |
| 0 | 393 break; |
| 394 case 4: | |
| 12 | 395 tmp = state->GPRM[reg] - data; |
| 396 if(tmp < 0) tmp = 0; | |
| 397 state->GPRM[reg] = (uint16_t)tmp; | |
| 0 | 398 break; |
| 399 case 5: | |
| 12 | 400 tmp = state->GPRM[reg] * data; |
| 401 if(tmp >= shortmax) tmp = shortmax; | |
| 402 state->GPRM[reg] = (uint16_t)tmp; | |
| 0 | 403 break; |
| 404 case 6: | |
| 12 | 405 if (data != 0) { |
| 406 state->GPRM[reg] /= data; | |
| 407 } else { | |
| 408 state->GPRM[reg] = 0; /* Avoid that divide by zero! */ | |
| 409 } | |
| 0 | 410 break; |
| 411 case 7: | |
| 412 state->GPRM[reg] %= data; | |
| 413 break; | |
| 414 case 8: /* SPECIAL CASE - RND! */ | |
| 12 | 415 state->GPRM[reg] = (uint16_t) ((float) data * rand()/(RAND_MAX+1.0)); |
| 0 | 416 break; |
| 417 case 9: | |
| 418 state->GPRM[reg] &= data; | |
| 419 break; | |
| 420 case 10: | |
| 421 state->GPRM[reg] |= data; | |
| 422 break; | |
| 423 case 11: | |
| 424 state->GPRM[reg] ^= data; | |
| 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) { | |
| 437 eval_set_op(op, reg, reg2, data); | |
| 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) { | |
| 450 eval_set_op(op, reg, reg2, data); | |
| 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 */ | |
| 12 | 458 static int32_t eval_command(uint8_t *bytes, link_t *return_values) { |
| 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; | |
| 0 | 470 memset(return_values, 0, sizeof(link_t)); |
| 471 | |
| 12 | 472 switch(new_bits(&command, 0, 3)) { /* three first old_bits */ |
| 0 | 473 case 0: /* Special instructions */ |
| 12 | 474 cond = eval_if_version_1(&command); |
| 475 res = eval_special_instruction(&command, cond); | |
| 0 | 476 if(res == -1) { |
| 477 fprintf(stderr, "Unknown Instruction!\n"); | |
| 6 | 478 assert(0); |
| 0 | 479 } |
| 480 break; | |
| 481 case 1: /* Link/jump instructions */ | |
| 12 | 482 if(new_bits(&command, 3, 1)) { |
| 483 cond = eval_if_version_2(&command); | |
| 484 res = eval_jump_instruction(&command, cond, return_values); | |
| 0 | 485 } else { |
| 12 | 486 cond = eval_if_version_1(&command); |
| 487 res = eval_link_instruction(&command, cond, return_values); | |
| 0 | 488 } |
| 489 if(res) | |
| 490 res = -1; | |
| 491 break; | |
| 492 case 2: /* System set instructions */ | |
| 12 | 493 cond = eval_if_version_2(&command); |
| 494 res = eval_system_set(&command, cond, return_values); | |
| 0 | 495 if(res) |
| 496 res = -1; | |
| 497 break; | |
| 498 case 3: /* Set instructions, either Compare or Link may be used */ | |
| 12 | 499 cond = eval_if_version_3(&command); |
| 500 eval_set_version_1(&command, cond); | |
| 501 if(new_bits(&command, 12, 4)) { | |
| 502 res = eval_link_instruction(&command, cond, return_values); | |
| 0 | 503 } |
| 504 if(res) | |
| 505 res = -1; | |
| 506 break; | |
| 507 case 4: /* Set, Compare -> Link Sub-Instruction */ | |
| 12 | 508 eval_set_version_2(&command, /*True*/ 1); |
| 509 cond = eval_if_version_4(&command); | |
| 510 res = eval_link_subins(&command, cond, return_values); | |
| 0 | 511 if(res) |
| 512 res = -1; | |
| 513 break; | |
| 514 case 5: /* Compare -> (Set and Link Sub-Instruction) */ | |
| 12 | 515 cond = eval_if_version_4(&command); |
| 516 eval_set_version_2(&command, cond); | |
| 517 res = eval_link_subins(&command, cond, return_values); | |
| 0 | 518 if(res) |
| 519 res = -1; | |
| 520 break; | |
| 521 case 6: /* Compare -> Set, allways Link Sub-Instruction */ | |
| 12 | 522 cond = eval_if_version_4(&command); |
| 523 eval_set_version_2(&command, cond); | |
| 524 res = eval_link_subins(&command, /*True*/ 1, return_values); | |
| 0 | 525 if(res) |
| 526 res = -1; | |
| 527 break; | |
| 12 | 528 default: /* Unknown command */ |
| 529 fprintf(stderr, "WARNING: Unknown Command=%x\n", new_bits(&command, 0, 3)); | |
| 0 | 530 } |
| 531 /* Check if there are bits not yet examined */ | |
| 532 | |
| 12 | 533 if(command.instruction & ~ command.examined) { |
| 534 fprintf(stderr, " libdvdnav: decoder.c: [WARNING, unknown bits:"); | |
| 535 fprintf(stderr, " %08llx", (command.instruction & ~ command.examined) ); | |
| 536 fprintf(stderr, "]"); | |
| 0 | 537 } |
| 538 | |
| 539 return res; | |
| 540 } | |
| 541 | |
| 542 /* Evaluate a set of commands in the given register set (which is | |
| 543 * modified */ | |
| 12 | 544 int32_t vmEval_CMD(vm_cmd_t commands[], int32_t num_commands, |
| 0 | 545 registers_t *registers, link_t *return_values) { |
| 12 | 546 int32_t i = 0; |
| 547 int32_t total = 0; | |
| 0 | 548 |
| 549 state = registers; /* TODO FIXME */ | |
| 550 | |
| 551 #ifdef TRACE | |
| 552 /* DEBUG */ | |
|
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
553 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
|
554 vmPrint_registers( registers ); |
| 0 | 555 if(1) { |
| 12 | 556 int32_t i; |
|
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
557 fprintf(stderr, "libdvdnav: Full list of commands to execute\n"); |
| 0 | 558 for(i = 0; i < num_commands; i++) |
| 559 vmPrint_CMD(i, &commands[i]); | |
| 560 fprintf(stderr, "--------------------------------------------\n"); | |
| 561 } /* end DEBUG */ | |
|
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
562 if (1) { |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
563 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
|
564 } |
| 0 | 565 #endif |
| 566 | |
| 567 while(i < num_commands && total < 100000) { | |
| 12 | 568 int32_t line; |
| 0 | 569 |
|
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
570 #ifdef TRACE |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
571 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
|
572 #endif |
| 0 | 573 line = eval_command(&commands[i].bytes[0], return_values); |
| 574 | |
| 575 if (line < 0) { /* Link command */ | |
|
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
576 #ifdef TRACE |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
577 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
|
578 vmPrint_registers( registers ); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
579 #endif |
| 0 | 580 fprintf(stderr, "eval: Doing Link/Jump/Call\n"); |
| 581 return 1; | |
| 582 } | |
| 583 | |
| 584 if (line > 0) /* Goto command */ | |
| 585 i = line - 1; | |
| 586 else /* Just continue on the next line */ | |
| 587 i++; | |
| 588 | |
| 589 total++; | |
| 590 } | |
| 591 | |
| 592 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
|
593 #ifdef TRACE |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
594 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
|
595 vmPrint_registers( registers ); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
596 #endif |
| 0 | 597 return 0; |
| 598 } | |
| 599 | |
| 600 static char *linkcmd2str(link_cmd_t cmd) { | |
| 601 switch(cmd) { | |
| 602 case LinkNoLink: | |
| 603 return "LinkNoLink"; | |
| 604 case LinkTopC: | |
| 605 return "LinkTopC"; | |
| 606 case LinkNextC: | |
| 607 return "LinkNextC"; | |
| 608 case LinkPrevC: | |
| 609 return "LinkPrevC"; | |
| 610 case LinkTopPG: | |
| 611 return "LinkTopPG"; | |
| 612 case LinkNextPG: | |
| 613 return "LinkNextPG"; | |
| 614 case LinkPrevPG: | |
| 615 return "LinkPrevPG"; | |
| 616 case LinkTopPGC: | |
| 617 return "LinkTopPGC"; | |
| 618 case LinkNextPGC: | |
| 619 return "LinkNextPGC"; | |
| 620 case LinkPrevPGC: | |
| 621 return "LinkPrevPGC"; | |
| 622 case LinkGoUpPGC: | |
| 623 return "LinkGoUpPGC"; | |
| 624 case LinkTailPGC: | |
| 625 return "LinkTailPGC"; | |
| 626 case LinkRSM: | |
| 627 return "LinkRSM"; | |
| 628 case LinkPGCN: | |
| 629 return "LinkPGCN"; | |
| 630 case LinkPTTN: | |
| 631 return "LinkPTTN"; | |
| 632 case LinkPGN: | |
| 633 return "LinkPGN"; | |
| 634 case LinkCN: | |
| 635 return "LinkCN"; | |
| 636 case Exit: | |
| 637 return "Exit"; | |
| 638 case JumpTT: | |
| 639 return "JumpTT"; | |
| 640 case JumpVTS_TT: | |
| 641 return "JumpVTS_TT"; | |
| 642 case JumpVTS_PTT: | |
| 643 return "JumpVTS_PTT"; | |
| 644 case JumpSS_FP: | |
| 645 return "JumpSS_FP"; | |
| 646 case JumpSS_VMGM_MENU: | |
| 647 return "JumpSS_VMGM_MENU"; | |
| 648 case JumpSS_VTSM: | |
| 649 return "JumpSS_VTSM"; | |
| 650 case JumpSS_VMGM_PGC: | |
| 651 return "JumpSS_VMGM_PGC"; | |
| 652 case CallSS_FP: | |
| 653 return "CallSS_FP"; | |
| 654 case CallSS_VMGM_MENU: | |
| 655 return "CallSS_VMGM_MENU"; | |
| 656 case CallSS_VTSM: | |
| 657 return "CallSS_VTSM"; | |
| 658 case CallSS_VMGM_PGC: | |
| 659 return "CallSS_VMGM_PGC"; | |
| 660 case PlayThis: | |
| 661 return "PlayThis"; | |
| 662 } | |
| 663 return "*** (bug)"; | |
| 664 } | |
| 665 | |
| 666 void vmPrint_LINK(link_t value) { | |
| 667 char *cmd = linkcmd2str(value.command); | |
| 668 | |
| 669 switch(value.command) { | |
| 670 case LinkNoLink: | |
| 671 case LinkTopC: | |
| 672 case LinkNextC: | |
| 673 case LinkPrevC: | |
| 674 case LinkTopPG: | |
| 675 case LinkNextPG: | |
| 676 case LinkPrevPG: | |
| 677 case LinkTopPGC: | |
| 678 case LinkNextPGC: | |
| 679 case LinkPrevPGC: | |
| 680 case LinkGoUpPGC: | |
| 681 case LinkTailPGC: | |
| 682 case LinkRSM: | |
| 683 fprintf(stderr, "%s (button %d)\n", cmd, value.data1); | |
| 684 break; | |
| 685 case LinkPGCN: | |
| 686 case JumpTT: | |
| 687 case JumpVTS_TT: | |
| 688 case JumpSS_VMGM_MENU: /* == 2 -> Title Menu */ | |
| 689 case JumpSS_VMGM_PGC: | |
| 690 fprintf(stderr, "%s %d\n", cmd, value.data1); | |
| 691 break; | |
| 692 case LinkPTTN: | |
| 693 case LinkPGN: | |
| 694 case LinkCN: | |
| 695 fprintf(stderr, "%s %d (button %d)\n", cmd, value.data1, value.data2); | |
| 696 break; | |
| 697 case Exit: | |
| 698 case JumpSS_FP: | |
| 699 case PlayThis: /* Humm.. should we have this at all.. */ | |
| 700 fprintf(stderr, "%s\n", cmd); | |
| 701 break; | |
| 702 case JumpVTS_PTT: | |
| 703 fprintf(stderr, "%s %d:%d\n", cmd, value.data1, value.data2); | |
| 704 break; | |
| 705 case JumpSS_VTSM: | |
| 706 fprintf(stderr, "%s vts %d title %d menu %d\n", | |
| 707 cmd, value.data1, value.data2, value.data3); | |
| 708 break; | |
| 709 case CallSS_FP: | |
| 710 fprintf(stderr, "%s resume cell %d\n", cmd, value.data1); | |
| 711 break; | |
| 712 case CallSS_VMGM_MENU: /* == 2 -> Title Menu */ | |
| 713 case CallSS_VTSM: | |
| 714 fprintf(stderr, "%s %d resume cell %d\n", cmd, value.data1, value.data2); | |
| 715 break; | |
| 716 case CallSS_VMGM_PGC: | |
| 717 fprintf(stderr, "%s %d resume cell %d\n", cmd, value.data1, value.data2); | |
| 718 break; | |
| 719 } | |
| 720 } | |
|
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
721 |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
722 void vmPrint_registers( registers_t *registers ) { |
| 12 | 723 int32_t i; |
|
10
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
724 fprintf(stderr, " # "); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
725 for(i = 0; i < 24; i++) |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
726 fprintf(stderr, " %2d |", i); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
727 fprintf(stderr, "\nSRPMS: "); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
728 for(i = 0; i < 24; i++) |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
729 fprintf(stderr, "%04x|", registers->SPRM[i]); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
730 fprintf(stderr, "\nGRPMS: "); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
731 for(i = 0; i < 16; i++) |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
732 fprintf(stderr, "%04x|", registers->GPRM[i]); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
733 fprintf(stderr, "\nGmode: "); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
734 for(i = 0; i < 16; i++) |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
735 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
|
736 fprintf(stderr, "\n"); |
|
6f0fb88d1463
Added some debug info, to hopefully help in tracking bugs in libdvdnav.
jcdutton
parents:
6
diff
changeset
|
737 } |
