home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2001 September / PC-WELT 9-2001.ISO / software / hw / brennen / flask_src.exe / Input / IFOParser / print_ifo_vm.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-06  |  8.3 KB  |  465 lines

  1.  
  2. /*
  3.  * IFO VIRTUAL MACHINE
  4.  *
  5.  * Copyright (C) 2000  Thomas Mirlacher
  6.  *
  7.  * This program 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.  * This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.  * 
  21.  * The author may be reached as dent@cosy.sbg.ac.at, or
  22.  * Thomas Mirlacher, Jakob-Haringerstr. 2, A-5020 Salzburg,
  23.  * Austria
  24.  *
  25.  *------------------------------------------------------------
  26.  *
  27.  */
  28.  
  29.  
  30. #ifdef PARSER
  31. #include <stdio.h>
  32. #endif
  33. #include <sys/types.h>
  34. //#include <unistd.h>
  35. #include "ifo.h"
  36.  
  37. #include "misc.h"
  38. #include "decode.h"
  39.  
  40. typedef struct {
  41.     u_char    foo    : 4;
  42.     u_char    cmd    : 4;
  43.     u_char    sub_cmd    : 4;
  44.     u_char    cmp    : 4;
  45.     u_char    val5    : 8;
  46.     u_char    val4    : 8;
  47.     u_char    val3    : 8;
  48.     u_char    val2    : 8;
  49.     u_char    val1    : 8;
  50.     u_char    val0    : 8;
  51. } op_t;    
  52.  
  53.  
  54. static void _cmd_nop (u_char *ptr);
  55. static void _cmd_goto (u_char *ptr);
  56. static void _cmd_lnk (u_char *ptr);
  57. static void _cmd_jmp (u_char *ptr);
  58. static void _cmd_setsystem (u_char *ptr);
  59. static void _cmd_setsystem2 (u_char *ptr);
  60. static void _cmd_set (u_char *ptr);
  61. static void _cmd_set2 (u_char *ptr);
  62. static void _cmd_unknown (u_char *ptr);
  63.  
  64. static struct {
  65.     void (*cmd) (u_char *ptr);
  66. } cmd_switch[] = {
  67.     {_cmd_nop},
  68.     {_cmd_goto},
  69.     {_cmd_lnk},
  70.     {_cmd_jmp},
  71.     {_cmd_setsystem2},
  72.     {_cmd_setsystem},
  73.     {_cmd_set2},
  74.     {_cmd_set},
  75.     {_cmd_unknown},
  76.     {_cmd_unknown},
  77.     {_cmd_unknown},
  78.     {_cmd_unknown},
  79.     {_cmd_unknown},
  80.     {_cmd_unknown},
  81.     {_cmd_unknown},
  82.     {_cmd_unknown},
  83.     {_cmd_unknown},
  84.     {_cmd_unknown},
  85.     {_cmd_unknown},
  86.     {_cmd_unknown},
  87.     {_cmd_unknown},
  88. };
  89.  
  90.  
  91. /**
  92.  * System register
  93.  */
  94.  
  95. static void _PrintRegister (u_int reg)
  96. {
  97.     char reg_name[][80]={
  98.         "Menu_Language",
  99.         "Audio_Stream_#",
  100.         "SubPicture_Stream_#",
  101.         "Angle_#",
  102.         "Title_#",        // VTS_TTN
  103.         "VTS Title_#",
  104.         "PGC_#",
  105.         "PTT_#",
  106.         "Highlighted_Button_#",
  107.         "Nav_Timer",
  108.         "TimedPGC_#",
  109.         "Audio_Mixing_Mode_for_Karaoke",
  110.         "Country_Code_for_Parental_Mgmt",
  111.         "Parental_Level",
  112.         "Player_Video_Cfg",
  113.         "Player_Audio_Cfg",
  114.         "Initial_Language_for_Audio",
  115.         "Initial_Language_for_SPU",
  116.         "Initial_LanguageExt_for_Audio",
  117.         "Initial_LanguageExt_for_SPU",
  118.         "21", "22", "23", "24" };
  119.  
  120.  
  121. //DENT: check if registers are in range
  122.     if (reg & 0x80)
  123.         printf ("r[%s]", reg_name[reg-0x80]);
  124.     else 
  125.         printf ("r[%x]", reg);
  126.         
  127. }
  128.  
  129.  
  130. /**
  131.  *
  132.  */
  133.  
  134. static void _hexdump (u_char *ptr, u_int num)
  135. {
  136.     int i;
  137.  
  138.     for (i=8-num; i<8; i++)
  139.         printf ("%02x ", ptr[i]);
  140.     printf ("\t");    
  141. }
  142.  
  143.  
  144. /**
  145.  *
  146.  */
  147.  
  148. static char *_decode_calc (char val)
  149. {
  150.     static char calc_op[][10] = {
  151.         "=", 
  152.         "<->",    // swap
  153.         "+=",
  154.         "-=",
  155.         "*=",
  156.         "/=",
  157.         "%=",
  158.         "??",    // rnd
  159.         "&=",
  160.         "|=",
  161.         "^=",
  162.         "??",    // invalid
  163.         "??",    // invalid
  164.         "??",    // invalid
  165.         "??"};    // invalid
  166.  
  167.     return (char *) calc_op[val&0x0F];
  168. }
  169.  
  170.     
  171. /**
  172.  *
  173.  */
  174.  
  175. static void _dump_cmp (u_char *opcode)
  176. {
  177.     op_t *op = (op_t *) opcode;
  178.     u_int rval, lval;
  179.  
  180.     char cmp_op[][10] = {
  181.         "none",
  182.         "&&",
  183.         "==",
  184.         "!=",
  185.         ">=",
  186.         ">",
  187.         "<",
  188.         "<="};
  189.  
  190.     if (op->cmp) {
  191.         printf ("if (");
  192.  
  193.         if ((op->cmd == 0x02) || (op->cmd == 0x00)) {    // lnk, goto
  194.             lval = op->val4;
  195.             rval = op->val3<<8 | op->val2;
  196.         } else {
  197.             lval = op->val1;
  198.             rval = op->val0;
  199.         }
  200.  
  201.         _PrintRegister (lval);
  202.         printf (" %s ", cmp_op [op->cmp&0x07]);
  203.  
  204.         if (op->cmp & 0x08)
  205.             printf ("0x%02X", rval);
  206.         else 
  207.             _PrintRegister (rval);
  208.         printf (") ");
  209.     }
  210. }
  211.  
  212.  
  213. /**
  214.  *
  215.  */
  216.  
  217. static void _cmd_nop (u_char *opcode)
  218. {
  219.     op_t *op = (op_t *) opcode;
  220.  
  221.     switch (op->sub_cmd) {
  222.         case 1:
  223.             printf ("goto line #0x%02X", opcode[7]);
  224.             break;
  225.         case 2:
  226.             printf ("break");
  227.             break;
  228.         case 3:
  229.             printf ("setTmpPM");
  230.             break;
  231.         default:
  232.             printf ("nop");
  233.             break;
  234.     }
  235. }
  236.  
  237.  
  238. /**
  239.  *
  240.  */
  241.  
  242. static void _cmd_goto (u_char *opcode)
  243. {
  244.     printf ("goto line# 0x%02X", opcode[5]);
  245. }
  246.  
  247.  
  248. /**
  249.  *
  250.  */
  251.  
  252. static void _cmd_lnk (u_char *opcode)
  253. {
  254.     op_t *op = (op_t *) opcode;
  255.  
  256.     printf ("lnk to ");
  257.  
  258.     switch (op->sub_cmd) {
  259.         case 0x01:
  260.             printf ("SIns ");
  261.             _hexdump (opcode, 8);
  262.             break;
  263.  
  264.         case 0x04:
  265.             printf ("PGC 0x%02X", opcode[6]<<8 | opcode[7]);
  266.             break; 
  267.  
  268.         case 0x05:
  269.             printf ("PTT 0x%02X, highlight 0x%02X", (op->val1&0x03<<8)|op->val0, op->val0>>2);
  270.             break; 
  271.  
  272.         case 0x06:
  273.             printf ("Program 0x%02X this PGC", opcode[7]);
  274.             if (opcode[6])
  275.                 printf (", highlight 0x%02X", opcode[6]>>2);
  276.             break;
  277.  
  278.         case 0x07:
  279.             printf ("Cell 0x%02X this PGC", opcode[7]);
  280.             if (opcode[6])
  281.                 printf (", highlight 0x%02X", opcode[6]>>2);
  282.             break;
  283.     }
  284. }
  285.  
  286.  
  287. /**
  288.  *
  289.  */
  290.  
  291. static void _cmd_jmp (u_char *opcode)
  292. {
  293.     op_t *op = (op_t *) opcode;
  294.  
  295.     printf ("jmp ");
  296.  
  297.     switch (op->sub_cmd) {
  298.         case 0x01:
  299.             printf ("Exit");
  300.             break;
  301.         case 0x02:
  302.             printf ("VTS 0x%02X", opcode[5]);
  303.             break;
  304.         case 0x03:
  305.             printf ("This VTS Title 0x%02X", opcode[5]);
  306.             break;
  307.         case 0x05:
  308.             printf ("This VTS Title 0x%02X Part 0x%02X", opcode[5], opcode[2]<<8|opcode[3]);
  309.             break;
  310.         case 0x06:
  311.             printf ("in SystemSpace ");
  312.             switch (opcode[5]>>4) {
  313.                 case 0x00:
  314.                     printf ("to play first PGC");
  315.                     break;
  316.                 case 0x01: {
  317.                     printf ("to menu \"%s\"", decode_menuname (op->val2));
  318.                 }
  319.                     break;
  320.                 case 0x02:
  321.                     printf ("to VTS 0x%02X and TTN 0x%02X", opcode[3], opcode[4]);
  322.                     break;
  323.                 case 0x03:
  324.                     printf ("to VMGM PGC number 0x%02X", opcode[2]<<8 | opcode[3]);
  325.                     break;
  326.                 case 0x08:
  327.                     printf ("lu 0x%02X vts0x%02X menu \"%s\"", op->val4, op->val3, decode_menuname (op->val2));
  328.                     break;
  329.             }
  330.             break;
  331.         case 0x08:
  332.             switch(op->val2>>4) {
  333.                 case 0x00:
  334.                     printf ("system first pgc");
  335.                     break;
  336.                 case 0x01:
  337.                     printf ("system title menu");
  338.                     break;
  339.                 case 0x02:
  340.                     printf ("system menu \"%s\"", decode_menuname (op->val2));
  341.                     break;
  342.                 case 0x03:
  343.                     printf ("system vmg pgc %x ????", op->val5<<8|op->val4);
  344.                     break;
  345.                 case 0x08:
  346.                     printf ("system lu 0x%02X menu \"%s\"", opcode[4], decode_menuname (op->val2));
  347.                     break;
  348.                 case 0x0c:
  349.                     printf ("system vmg pgc 0x%02X", op->val5<<8|op->val4);
  350.                     break;
  351.             }
  352.             break;
  353.     }
  354. }
  355.  
  356.  
  357. /**
  358.  *
  359.  */
  360.  
  361. static void _cmd_set2 (u_char *opcode)
  362. {
  363.     op_t *op = (op_t *) opcode;
  364.  
  365.     _PrintRegister (op->val4);
  366.     printf (" %s ", _decode_calc (op->foo));
  367.     _PrintRegister (op->val2);
  368. }
  369.  
  370.  
  371. /**
  372.  *
  373.  */
  374.  
  375. static void _cmd_set (u_char *opcode)
  376. {
  377.     op_t *op = (op_t *) opcode;
  378.     _PrintRegister (op->val4);
  379.     printf (" %s ", _decode_calc (op->foo));
  380.     printf ("0x%04X", op->val3<<8 | op->val2);
  381. }
  382.  
  383.  
  384. /**
  385.  *
  386.  */
  387.  
  388. static void _cmd_setsystem2 (u_char *opcode)
  389. {
  390.     op_t *op = (op_t *) opcode;
  391.  
  392.     printf ("sys2: ");
  393.     _PrintRegister (op->val3);
  394.     printf (" %s ", _decode_calc (op->foo));
  395.     _PrintRegister (op->val2);
  396. }
  397.  
  398.  
  399. /**
  400.  *
  401.  */
  402.  
  403. static void _cmd_setsystem (u_char *opcode)
  404. {
  405.     op_t *op = (op_t *) opcode;
  406.  
  407.     _PrintRegister (op->val4);
  408.     printf (" %s ", _decode_calc (op->foo));
  409.     printf ("0x%04X", op->val3<<8 | op->val2);
  410. }
  411.  
  412.  
  413. /**
  414.  *
  415.  */
  416.  
  417. static void _cmd_unknown (u_char *opcode)
  418. {
  419.     printf ("unknown");
  420. }
  421.  
  422.  
  423. /**
  424.  * 8 bytes opcode
  425.  */
  426.  
  427. void ifoPrintVMOP (u_char *opcode)
  428. {
  429.     op_t *op = (op_t *) opcode;
  430.     u_char *ptr = opcode;
  431.  
  432.     _hexdump (opcode, 8);
  433.  
  434. // do we have a compare operation?
  435.     _dump_cmp (opcode);
  436.  
  437.     cmd_switch [op->cmd].cmd (opcode);
  438.     printf (";");
  439.  
  440. #if 0
  441.     switch (op->cmd) {
  442.     case CMD_GOTO: {
  443.         printf ("goto line 0x%04X", ptr[6]<<8|ptr[7]);
  444.     }
  445.     break;
  446.     //case 0x61: 
  447.     case CMD_SET_SYSTEM: { // SetSystem
  448.         printf ("r[%x] ", ptr[3]);
  449.         printf (" %s ", _decode_calc (op->cmp));
  450.         _PrintRegister (ptr[5]);
  451.         //printf (" 0x%04X", ptr[4]<<8|ptr[5]);
  452.     }
  453.     break;    
  454.     case 0x70: { // SetSystem
  455.         _PrintRegister (ptr[3]);
  456.         printf (" %s ", _decode_calc(op->cmp));
  457.         printf (" 0x%04X", ptr[4]<<8|ptr[5]);
  458.     }
  459.     break;
  460.     default:
  461.         _hexdump (opcode, 8);
  462.     }
  463. #endif
  464. }
  465.