1 /*****************************************************************************
2 * dvd_ifo.c: Functions for ifo parsing
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: dvd_ifo.c,v 1.13 2001/02/20 07:49:12 sam Exp $
7 * Author: Stéphane Borel <stef@via.ecp.fr>
10 * - libifo by Thomas Mirlacher <dent@cosy.sbg.ac.at>
11 * - IFO structure documentation by Thomas Mirlacher, Björn Englund,
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
27 *****************************************************************************/
29 /*****************************************************************************
31 *****************************************************************************/
43 #include "input_dvd.h"
48 static vmg_t ReadVMG ( ifo_t* );
49 void CommandRead( ifo_command_t );
55 /*****************************************************************************
56 * IfoInit : Creates an ifo structure and prepares for parsing directly
58 *****************************************************************************/
59 ifo_t IfoInit( int i_fd )
64 /* If we are here the dvd device has already been opened */
67 i_lba = UDFFindFile( i_fd, "/VIDEO_TS/VIDEO_TS.IFO");
69 ifo.i_off = (off_t)(i_lba) * DVD_LB_SIZE;
70 ifo.i_pos = lseek( ifo.i_fd, ifo.i_off, SEEK_SET );
72 /* Video Manager Initialization */
73 intf_WarnMsg( 2, "ifo: initializing VMG" );
74 ifo.vmg = ReadVMG( &ifo );
79 /*****************************************************************************
80 * IfoEnd : Frees all the memory allocated to ifo structures
81 *****************************************************************************/
82 void IfoEnd( ifo_t* p_ifo )
87 /* Free structures from video title sets */
88 for( j=0 ; j<p_ifo->vmg.mat.i_tts_nb ; j++ )
90 free( p_ifo->p_vts[j].vobu_admap.pi_vobu_ssector );
91 free( p_ifo->p_vts[j].c_adt.p_cell_inf );
92 free( p_ifo->p_vts[j].m_vobu_admap.pi_vobu_ssector );
93 free( p_ifo->p_vts[j].m_c_adt.p_cell_inf );
94 for( i=0 ; i<p_ifo->p_vts[j].tmap_ti.i_nb ; i++ )
96 free( p_ifo->p_vts[j].tmap_ti.p_tmap[i].pi_sector );
98 free( p_ifo->p_vts[j].tmap_ti.pi_sbyte );
99 free( p_ifo->p_vts[j].tmap_ti.p_tmap );
100 free( p_ifo->p_vts[j].pgci_ti.p_srp );
101 for( i=0 ; i<p_ifo->p_vts[j].pgci_ut.i_lu_nb ; i++ )
103 free( p_ifo->p_vts[j].pgci_ut.p_pgci_inf[i].p_srp );
105 free( p_ifo->p_vts[j].pgci_ut.p_pgci_inf );
106 free( p_ifo->p_vts[j].pgci_ut.p_lu );
109 free( p_ifo->p_vts );
111 /* Free structures from video manager */
112 free( p_ifo->vmg.vobu_admap.pi_vobu_ssector );
113 free( p_ifo->vmg.c_adt.p_cell_inf );
114 for( i=0 ; i<p_ifo->vmg.pgci_ut.i_lu_nb ; i++ )
116 free( p_ifo->vmg.pgci_ut.p_pgci_inf[i].p_srp );
118 free( p_ifo->vmg.pgci_ut.p_pgci_inf );
119 free( p_ifo->vmg.pgci_ut.p_lu );
120 for( i=1 ; i<=8 ; i++ )
122 free( p_ifo->vmg.ptl_mait.p_ptl_mask->ppi_ptl_mask[i] );
124 free( p_ifo->vmg.ptl_mait.p_ptl_desc );
125 free( p_ifo->vmg.ptl_mait.p_ptl_mask );
126 free( p_ifo->vmg.vts_atrt.pi_vts_atrt_sbyte );
127 free( p_ifo->vmg.vts_atrt.p_vts_atrt );
128 free( p_ifo->vmg.pgc.p_cell_pos_inf );
129 free( p_ifo->vmg.pgc.p_cell_play_inf );
130 free( p_ifo->vmg.pgc.prg_map.pi_entry_cell );
131 free( p_ifo->vmg.pgc.com_tab.p_cell_com );
132 free( p_ifo->vmg.pgc.com_tab.p_post_com );
133 free( p_ifo->vmg.pgc.com_tab.p_pre_com );
139 * Macros to process ifo files
142 #define GET( p_field , i_len ) \
144 read( p_ifo->i_fd , (p_field) , (i_len) ); \
145 /*fprintf(stderr, "Pos : %lld Val : %llx\n", \
146 (long long)(p_ifo->i_pos - i_start), \
147 (long long)*(p_field) ); */ \
148 p_ifo->i_pos += i_len; \
151 #define GETC( p_field ) \
153 read( p_ifo->i_fd , (p_field) , 1 ); \
154 /*fprintf(stderr, "Pos : %lld Value : %d\n", \
155 (long long)(p_ifo->i_pos - i_start), \
160 #define GETS( p_field ) \
162 read( p_ifo->i_fd , (p_field) , 2 ); \
163 *(p_field) = ntohs( *(p_field) ); \
164 /*fprintf(stderr, "Pos : %lld Value : %d\n", \
165 (long long)(p_ifo->i_pos - i_start), \
170 #define GETL( p_field ) \
172 read( p_ifo->i_fd , (p_field) , 4 ); \
173 *(p_field) = ntohl( *(p_field) ); \
174 /*fprintf(stderr, "Pos : %lld Value : %d\n", \
175 (long long)(p_ifo->i_pos - i_start), \
180 #define GETLL( p_field ) \
182 read( p_ifo->i_fd , (p_field) , 8 ); \
183 *(p_field) = ntoh64( *(p_field) ); \
184 /*fprintf(stderr, "Pos : %lld Value : %lld\n", \
185 (long long)(p_ifo->i_pos - i_start), \
190 #define FLUSH( i_len ) \
192 /*fprintf(stderr, "Pos : %lld\n", (long long)(p_ifo->i_pos - i_start));*/ \
193 p_ifo->i_pos = lseek( p_ifo->i_fd , \
194 p_ifo->i_pos + (i_len), SEEK_SET ); \
198 * Function common to Video Manager and Video Title set Processing
201 /*****************************************************************************
202 * ReadPGC : Fills the Program Chain structure.
203 *****************************************************************************/
204 #define GETCOMMAND( p_com ) \
206 read( p_ifo->i_fd , (p_com) , 8 ); \
207 /*fprintf(stderr, "Pos : %lld Type : %d direct : %d cmd : %d dircmp : %d cmp : %d subcmd : %d v0 : %d v2 : %d v4 : %d\n", \
208 (long long)(p_ifo->i_pos - i_start), \
209 (int)((p_com)->i_type), \
210 (int)((p_com)->i_direct), \
211 (int)((p_com)->i_cmd), \
212 (int)((p_com)->i_dir_cmp), \
213 (int)((p_com)->i_cmp), \
214 (int)((p_com)->i_sub_cmd), \
215 (int)((p_com)->data.pi_16[0]), \
216 (int)((p_com)->data.pi_16[1]), \
217 (int)((p_com)->data.pi_16[2]));*/ \
218 /* CommandRead( *(p_com) );*/ \
222 static pgc_t ReadPGC( ifo_t* p_ifo )
226 off_t i_start = p_ifo->i_pos;
228 //fprintf( stderr, "PGC\n" );
231 GETC( &pgc.i_prg_nb );
232 GETC( &pgc.i_cell_nb );
233 //fprintf( stderr, "PGC: Prg: %d Cell: %d\n", pgc.i_prg_nb, pgc.i_cell_nb );
234 GETL( &pgc.i_play_time );
235 GETL( &pgc.i_prohibited_user_op );
236 for( i=0 ; i<8 ; i++ )
238 GETS( &pgc.pi_audio_status[i] );
240 for( i=0 ; i<32 ; i++ )
242 GETL( &pgc.pi_subpic_status[i] );
244 GETS( &pgc.i_next_pgc_nb );
245 GETS( &pgc.i_prev_pgc_nb );
246 GETS( &pgc.i_goup_pgc_nb );
247 //fprintf( stderr, "PGC: Prev: %d Next: %d Up: %d\n",pgc.i_prev_pgc_nb ,pgc.i_next_pgc_nb, pgc.i_goup_pgc_nb );
248 GETC( &pgc.i_still_time );
249 GETC( &pgc.i_play_mode );
250 for( i=0 ; i<16 ; i++ )
252 GETL( &pgc.pi_yuv_color[i] );
253 /* FIXME : We have to erase the extra bit */
255 GETS( &pgc.i_com_tab_sbyte );
256 GETS( &pgc.i_prg_map_sbyte );
257 GETS( &pgc.i_cell_play_inf_sbyte );
258 GETS( &pgc.i_cell_pos_inf_sbyte );
260 /* Parsing of pgc_com_tab_t */
261 if( pgc.i_com_tab_sbyte )
263 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start
264 + pgc.i_com_tab_sbyte, SEEK_SET );
265 GETS( &pgc.com_tab.i_pre_com_nb );
266 GETS( &pgc.com_tab.i_post_com_nb );
267 GETS( &pgc.com_tab.i_cell_com_nb );
269 if( pgc.com_tab.i_pre_com_nb )
271 pgc.com_tab.p_pre_com =
272 malloc(pgc.com_tab.i_pre_com_nb *sizeof(ifo_command_t));
273 if( pgc.com_tab.p_pre_com == NULL )
275 intf_ErrMsg( "Out of memory" );
279 for( i=0 ; i<pgc.com_tab.i_pre_com_nb ; i++ )
281 GETCOMMAND( &pgc.com_tab.p_pre_com[i] );
284 if( pgc.com_tab.i_post_com_nb )
286 pgc.com_tab.p_post_com =
287 malloc(pgc.com_tab.i_post_com_nb *sizeof(ifo_command_t));
288 if( pgc.com_tab.p_post_com == NULL )
290 intf_ErrMsg( "Out of memory" );
294 for( i=0 ; i<pgc.com_tab.i_post_com_nb ; i++ )
296 GETCOMMAND( &pgc.com_tab.p_post_com[i] );
299 if( pgc.com_tab.i_cell_com_nb )
301 pgc.com_tab.p_cell_com =
302 malloc(pgc.com_tab.i_cell_com_nb *sizeof(ifo_command_t));
303 if( pgc.com_tab.p_cell_com == NULL )
305 intf_ErrMsg( "Out of memory" );
309 for( i=0 ; i<pgc.com_tab.i_cell_com_nb ; i++ )
311 GETCOMMAND( &pgc.com_tab.p_cell_com[i] );
315 /* Parsing of pgc_prg_map_t */
316 if( pgc.i_prg_map_sbyte )
318 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start
319 + pgc.i_prg_map_sbyte, SEEK_SET );
320 pgc.prg_map.pi_entry_cell = malloc( pgc.i_prg_nb *sizeof(u8) );
321 if( pgc.prg_map.pi_entry_cell == NULL )
323 intf_ErrMsg( "Out of memory" );
327 GET( pgc.prg_map.pi_entry_cell, pgc.i_prg_nb );
328 /* FIXME : check endianness here */
330 /* Parsing of cell_play_inf_t */
331 if( pgc.i_cell_play_inf_sbyte )
333 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start
334 + pgc.i_cell_play_inf_sbyte, SEEK_SET );
335 pgc.p_cell_play_inf = malloc( pgc.i_cell_nb *sizeof(cell_play_inf_t) );
336 if( pgc.p_cell_play_inf == NULL )
338 intf_ErrMsg( "Out of memory" );
342 for( i=0 ; i<pgc.i_cell_nb ; i++ )
344 GETS( &pgc.p_cell_play_inf[i].i_cat );
345 GETC( &pgc.p_cell_play_inf[i].i_still_time );
346 GETC( &pgc.p_cell_play_inf[i].i_com_nb );
347 GETL( &pgc.p_cell_play_inf[i].i_play_time );
348 GETL( &pgc.p_cell_play_inf[i].i_entry_sector );
349 GETL( &pgc.p_cell_play_inf[i].i_first_ilvu_vobu_esector );
350 GETL( &pgc.p_cell_play_inf[i].i_lvobu_ssector );
351 GETL( &pgc.p_cell_play_inf[i].i_lsector );
354 /* Parsing of cell_pos_inf_map */
355 if( pgc.i_cell_pos_inf_sbyte )
357 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start
358 + pgc.i_cell_pos_inf_sbyte, SEEK_SET );
359 pgc.p_cell_pos_inf = malloc( pgc.i_cell_nb *sizeof(cell_pos_inf_t) );
360 if( pgc.p_cell_pos_inf == NULL )
362 intf_ErrMsg( "Out of memory" );
366 for( i=0 ; i<pgc.i_cell_nb ; i++ )
368 GETS( &pgc.p_cell_pos_inf[i].i_vob_id );
370 GETC( &pgc.p_cell_pos_inf[i].i_cell_id );
377 /*****************************************************************************
378 * ReadUnit : Fills Menu Language Unit Table/ PGC Info Table
379 *****************************************************************************/
380 static pgci_inf_t ReadUnit( ifo_t* p_ifo )
384 off_t i_start = p_ifo->i_pos;
386 //fprintf( stderr, "Unit\n" );
388 GETS( &inf.i_srp_nb );
390 GETL( &inf.i_lu_ebyte );
391 inf.p_srp = malloc( inf.i_srp_nb *sizeof(pgci_srp_t) );
392 if( inf.p_srp == NULL )
394 intf_ErrMsg( "Out of memory" );
398 for( i=0 ; i<inf.i_srp_nb ; i++ )
400 GETC( &inf.p_srp[i].i_pgc_cat_mask );
401 GETC( &inf.p_srp[i].i_pgc_cat );
402 GETS( &inf.p_srp[i].i_par_mask );
403 GETL( &inf.p_srp[i].i_pgci_sbyte );
405 for( i=0 ; i<inf.i_srp_nb ; i++ )
407 p_ifo->i_pos = lseek( p_ifo->i_fd,
408 i_start + inf.p_srp[i].i_pgci_sbyte,
410 //fprintf( stderr, "Unit: PGC %d\n", i );
411 inf.p_srp[i].pgc = ReadPGC( p_ifo );
417 /*****************************************************************************
418 * ReadUnitTable : Fills the PGCI Unit structure.
419 *****************************************************************************/
420 static pgci_ut_t ReadUnitTable( ifo_t* p_ifo )
424 off_t i_start = p_ifo->i_pos;
426 //fprintf( stderr, "Unit Table\n" );
428 GETS( &pgci.i_lu_nb );
430 GETL( &pgci.i_ebyte );
431 pgci.p_lu = malloc( pgci.i_lu_nb *sizeof(pgci_lu_t) );
432 if( pgci.p_lu == NULL )
434 intf_ErrMsg( "Out of memory" );
438 for( i=0 ; i<pgci.i_lu_nb ; i++ )
440 GET( pgci.p_lu[i].ps_lang_code, 2 );
442 GETC( &pgci.p_lu[i].i_existence_mask );
443 GETL( &pgci.p_lu[i].i_lu_sbyte );
445 pgci.p_pgci_inf = malloc( pgci.i_lu_nb *sizeof(pgci_inf_t) );
446 if( pgci.p_pgci_inf == NULL )
448 intf_ErrMsg( "Out of memory" );
452 for( i=0 ; i<pgci.i_lu_nb ; i++ )
454 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start +
455 pgci.p_lu[i].i_lu_sbyte,
457 pgci.p_pgci_inf[i] = ReadUnit( p_ifo );
463 /*****************************************************************************
464 * ReadCellInf : Fills the Cell Information structure.
465 *****************************************************************************/
466 static c_adt_t ReadCellInf( ifo_t* p_ifo )
469 off_t i_start = p_ifo->i_pos;
472 //fprintf( stderr, "CELL ADD\n" );
474 GETS( &c_adt.i_vob_nb );
476 GETL( &c_adt.i_ebyte );
478 ( i_start + c_adt.i_ebyte + 1 - p_ifo->i_pos ) / sizeof(cell_inf_t);
479 c_adt.p_cell_inf = malloc( c_adt.i_cell_nb *sizeof(cell_inf_t) );
480 if( c_adt.p_cell_inf == NULL )
482 intf_ErrMsg( "Out of memory" );
486 for( i = 0 ; i < c_adt.i_cell_nb ; i++ )
488 GETS( &c_adt.p_cell_inf[i].i_vob_id );
489 GETC( &c_adt.p_cell_inf[i].i_cell_id );
491 GETL( &c_adt.p_cell_inf[i].i_ssector );
492 GETL( &c_adt.p_cell_inf[i].i_esector );
498 /*****************************************************************************
499 * ReadMap : Fills the VOBU Map structure.
500 *****************************************************************************/
501 static vobu_admap_t ReadMap( ifo_t* p_ifo )
505 off_t i_start = p_ifo->i_pos;
507 //fprintf( stderr, "VOBU ADMAP\n" );
509 GETL( &map.i_ebyte );
510 i_max = ( i_start + map.i_ebyte + 1 - p_ifo->i_pos ) / sizeof(u32);
511 map.pi_vobu_ssector = malloc( i_max *sizeof(u32) );
512 for( i=0 ; i<i_max ; i++ )
514 GETL( &map.pi_vobu_ssector[i] );
521 * Video Manager Information Processing.
522 * This is what is contained in video_ts.ifo.
525 /*****************************************************************************
526 * ReadVMGInfMat : Fills the Management Information structure.
527 *****************************************************************************/
528 static vmgi_mat_t ReadVMGInfMat( ifo_t* p_ifo )
532 // off_t i_start = p_ifo->i_pos;
534 //fprintf( stderr, "VMGI\n" );
536 GET( mat.psz_id , 12 );
537 mat.psz_id[12] = '\0';
538 GETL( &mat.i_lsector );
540 GETL( &mat.i_i_lsector );
542 GETC( &mat.i_spec_ver );
544 GETS( &mat.i_vol_nb );
546 GETC( &mat.i_disc_side );
548 GETS( &mat.i_tts_nb );
549 GET( mat.ps_provider_id, 32 );
550 GETLL( &mat.i_pos_code );
552 GETL( &mat.i_i_mat_ebyte );
553 GETL( &mat.i_fp_pgc_sbyte );
555 GETL( &mat.i_vobs_ssector );
556 GETL( &mat.i_ptt_srpt_ssector );
557 GETL( &mat.i_pgci_ut_ssector );
558 GETL( &mat.i_ptl_mait_ssector );
559 GETL( &mat.i_vts_atrt_ssector );
560 GETL( &mat.i_txtdt_mg_ssector );
561 GETL( &mat.i_c_adt_ssector );
562 GETL( &mat.i_vobu_admap_ssector );
564 GETS( &mat.i_video_atrt );
566 GETC( &mat.i_audio_nb );
567 //fprintf( stderr, "vmgi audio nb : %d\n", mat.i_audio_nb );
568 for( i=0 ; i < 8 ; i++ )
570 GETLL( &mat.pi_audio_atrt[i] );
573 GETC( &mat.i_subpic_nb );
574 //fprintf( stderr, "vmgi subpic nb : %d\n", mat.i_subpic_nb );
575 for( i=0 ; i < mat.i_subpic_nb ; i++ )
577 GET( &mat.pi_subpic_atrt[i], 6 );
578 /* FIXME : take care of endianness */
584 /*****************************************************************************
585 * ReadVMGTitlePointer : Fills the Part Of Title Search Pointer structure.
586 *****************************************************************************/
587 static vmg_ptt_srpt_t ReadVMGTitlePointer( ifo_t* p_ifo )
591 // off_t i_start = p_ifo->i_pos;
593 //fprintf( stderr, "PTR\n" );
595 GETS( &ptr.i_ttu_nb );
596 //fprintf( stderr, "PTR: TTU nb %d\n", ptr.i_ttu_nb );
598 GETL( &ptr.i_ebyte );
600 ptr.p_tts = malloc( ptr.i_ttu_nb *sizeof(tts_t) );
601 if( ptr.p_tts == NULL )
603 intf_ErrMsg( "Out of memory" );
607 for( i=0 ; i<ptr.i_ttu_nb ; i++ )
609 GETC( &ptr.p_tts[i].i_play_type );
610 GETC( &ptr.p_tts[i].i_angle_nb );
611 GETS( &ptr.p_tts[i].i_ptt_nb );
612 GETS( &ptr.p_tts[i].i_parental_id );
613 GETC( &ptr.p_tts[i].i_tts_nb );
614 GETC( &ptr.p_tts[i].i_vts_ttn );
615 GETL( &ptr.p_tts[i].i_ssector );
616 //fprintf( stderr, "PTR: %d %d %d\n", ptr.p_tts[i].i_ptt_nb, ptr.p_tts[i].i_tts_nb,ptr.p_tts[i].i_vts_ttn );
622 /*****************************************************************************
623 * ReadParentalInf : Fills the Parental Management structure.
624 *****************************************************************************/
625 static vmg_ptl_mait_t ReadParentalInf( ifo_t* p_ifo )
629 off_t i_start = p_ifo->i_pos;
631 //fprintf( stderr, "PTL\n" );
633 GETS( &par.i_country_nb );
634 GETS( &par.i_vts_nb );
635 GETL( &par.i_ebyte );
636 par.p_ptl_desc = malloc( par.i_country_nb *sizeof(vmg_ptl_mai_desc_t) );
637 if( par.p_ptl_desc == NULL )
639 intf_ErrMsg( "Out of memory" );
643 for( i=0 ; i<par.i_country_nb ; i++ )
645 GET( par.p_ptl_desc[i].ps_country_code, 2 );
647 GETS( &par.p_ptl_desc[i].i_ptl_mai_sbyte );
650 par.p_ptl_mask = malloc( par.i_country_nb *sizeof(vmg_ptl_mask_t) );
651 if( par.p_ptl_mask == NULL )
653 intf_ErrMsg( "Out of memory" );
657 for( i=0 ; i<par.i_country_nb ; i++ )
659 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start +
660 par.p_ptl_desc[i].i_ptl_mai_sbyte, SEEK_SET );
661 for( j=1 ; j<=8 ; j++ )
663 par.p_ptl_mask[i].ppi_ptl_mask[j] =
664 malloc( par.i_vts_nb *sizeof(u16) );
665 if( par.p_ptl_mask[i].ppi_ptl_mask[j] == NULL )
667 intf_ErrMsg( "Out of memory" );
671 for( k=0 ; k<par.i_vts_nb ; k++ )
673 GETS( &par.p_ptl_mask[i].ppi_ptl_mask[j][k] );
681 /*****************************************************************************
682 * ReadVTSAttr : Fills the structure about VTS attributes.
683 *****************************************************************************/
684 static vmg_vts_atrt_t ReadVTSAttr( ifo_t* p_ifo )
688 off_t i_start = p_ifo->i_pos;
690 //fprintf( stderr, "VTS ATTR\n" );
692 GETS( &atrt.i_vts_nb );
693 //fprintf( stderr, "VTS ATTR Nb: %d\n", atrt.i_vts_nb );
695 GETL( &atrt.i_ebyte );
696 atrt.pi_vts_atrt_sbyte = malloc( atrt.i_vts_nb *sizeof(u32) );
697 if( atrt.pi_vts_atrt_sbyte == NULL )
699 intf_ErrMsg( "Out of memory" );
703 for( i=0 ; i<atrt.i_vts_nb ; i++ )
705 GETL( &atrt.pi_vts_atrt_sbyte[i] );
707 atrt.p_vts_atrt = malloc( atrt.i_vts_nb *sizeof(vts_atrt_t) );
708 if( atrt.p_vts_atrt == NULL )
710 intf_ErrMsg( "Out of memory" );
714 for( i=0 ; i<atrt.i_vts_nb ; i++ )
716 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start +
717 atrt.pi_vts_atrt_sbyte[i],
719 GETL( &atrt.p_vts_atrt[i].i_ebyte );
720 GETL( &atrt.p_vts_atrt[i].i_cat_app_type );
721 GETS( &atrt.p_vts_atrt[i].i_vtsm_video_atrt );
723 GETC( &atrt.p_vts_atrt[i].i_vtsm_audio_nb );
724 //fprintf( stderr, "m audio nb : %d\n", atrt.p_vts_atrt[i].i_vtsm_audio_nb );
725 for( j=0 ; j<8 ; j++ )
727 GETLL( &atrt.p_vts_atrt[i].pi_vtsm_audio_atrt[j] );
730 GETC( &atrt.p_vts_atrt[i].i_vtsm_subpic_nb );
731 //fprintf( stderr, "m subp nb : %d\n", atrt.p_vts_atrt[i].i_vtsm_subpic_nb );
732 for( j=0 ; j<28 ; j++ )
734 GET( &atrt.p_vts_atrt[i].pi_vtsm_subpic_atrt[j], 6 );
735 /* FIXME : Fix endianness issue here */
738 GETS( &atrt.p_vts_atrt[i].i_vtstt_video_atrt );
740 GETL( &atrt.p_vts_atrt[i].i_vtstt_audio_nb );
741 //fprintf( stderr, "tt audio nb : %d\n", atrt.p_vts_atrt[i].i_vtstt_audio_nb );
742 for( j=0 ; j<8 ; j++ )
744 GETLL( &atrt.p_vts_atrt[i].pi_vtstt_audio_atrt[j] );
747 GETC( &atrt.p_vts_atrt[i].i_vtstt_subpic_nb );
748 //fprintf( stderr, "tt subp nb : %d\n", atrt.p_vts_atrt[i].i_vtstt_subpic_nb );
749 for( j=0 ; j<28/*atrt.p_vts_atrt[i].i_vtstt_subpic_nb*/ ; j++ )
751 GET( &atrt.p_vts_atrt[i].pi_vtstt_subpic_atrt[j], 6 );
752 /* FIXME : Fix endianness issue here */
759 /*****************************************************************************
760 * ReadVMG : Parse video_ts.ifo file to fill the Video Manager structure.
761 *****************************************************************************/
762 static vmg_t ReadVMG( ifo_t* p_ifo )
766 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off, SEEK_SET);
767 vmg.mat = ReadVMGInfMat( p_ifo );
768 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
769 vmg.mat.i_fp_pgc_sbyte, SEEK_SET );
770 vmg.pgc = ReadPGC( p_ifo );
771 if( vmg.mat.i_ptt_srpt_ssector )
773 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
774 vmg.mat.i_ptt_srpt_ssector *DVD_LB_SIZE,
776 vmg.ptt_srpt = ReadVMGTitlePointer( p_ifo );
778 if( vmg.mat.i_pgci_ut_ssector )
780 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
781 vmg.mat.i_pgci_ut_ssector *DVD_LB_SIZE,
783 vmg.pgci_ut = ReadUnitTable( p_ifo );
785 if( vmg.mat.i_ptl_mait_ssector )
787 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
788 vmg.mat.i_ptl_mait_ssector *DVD_LB_SIZE,
790 vmg.ptl_mait = ReadParentalInf( p_ifo );
792 if( vmg.mat.i_vts_atrt_ssector )
794 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
795 vmg.mat.i_vts_atrt_ssector *DVD_LB_SIZE,
797 vmg.vts_atrt = ReadVTSAttr( p_ifo );
799 if( vmg.mat.i_c_adt_ssector )
801 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
802 vmg.mat.i_c_adt_ssector *DVD_LB_SIZE,
804 vmg.c_adt = ReadCellInf( p_ifo );
806 if( vmg.mat.i_vobu_admap_ssector )
808 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
809 vmg.mat.i_vobu_admap_ssector *DVD_LB_SIZE,
811 vmg.vobu_admap = ReadMap( p_ifo );
817 * Video Title Set Information Processing.
818 * This is what is contained in vts_*.ifo.
821 /*****************************************************************************
822 * ReadVTSInfMat : Fills the Title Set Information structure.
823 *****************************************************************************/
824 static vtsi_mat_t ReadVTSInfMat( ifo_t* p_ifo )
828 // off_t i_start = p_ifo->i_pos;
830 //fprintf( stderr, "VTSI\n" );
832 GET( mat.psz_id , 12 );
833 mat.psz_id[12] = '\0';
834 GETL( &mat.i_lsector );
836 GETL( &mat.i_i_lsector );
838 GETC( &mat.i_spec_ver );
841 GETL( &mat.i_mat_ebyte );
843 GETL( &mat.i_m_vobs_ssector );
844 GETL( &mat.i_tt_vobs_ssector );
845 GETL( &mat.i_ptt_srpt_ssector );
846 GETL( &mat.i_pgcit_ssector );
847 GETL( &mat.i_m_pgci_ut_ssector );
848 GETL( &mat.i_tmap_ti_ssector );
849 GETL( &mat.i_m_c_adt_ssector );
850 GETL( &mat.i_m_vobu_admap_ssector );
851 GETL( &mat.i_c_adt_ssector );
852 GETL( &mat.i_vobu_admap_ssector );
854 GETS( &mat.i_m_video_atrt );
856 GETC( &mat.i_m_audio_nb );
857 for( i=0 ; i<8 ; i++ )
859 GETLL( &mat.pi_m_audio_atrt[i] );
862 GETC( &mat.i_m_subpic_nb );
863 for( i=0 ; i<28 ; i++ )
865 GET( &mat.pi_m_subpic_atrt[i], 6 );
866 /* FIXME : take care of endianness */
869 GETS( &mat.i_video_atrt );
871 GETC( &mat.i_audio_nb );
872 //fprintf( stderr, "vtsi audio nb : %d\n", mat.i_audio_nb );
873 for( i=0 ; i<8 ; i++ )
875 GETLL( &mat.pi_audio_atrt[i] );
878 GETC( &mat.i_subpic_nb );
879 //fprintf( stderr, "vtsi subpic nb : %d\n", mat.i_subpic_nb );
880 for( i=0 ; i<mat.i_subpic_nb ; i++ )
882 GET( &mat.pi_subpic_atrt[i], 6 );
883 /* FIXME : take care of endianness */
889 /*****************************************************************************
890 * ReadVTSTitlePointer : Fills the Part Of Title Search Pointer structure.
891 *****************************************************************************/
892 static vts_ptt_srpt_t ReadVTSTitlePointer( ifo_t* p_ifo )
896 off_t i_start = p_ifo->i_pos;
898 //fprintf( stderr, "VTS PTR\n" );
900 GETS( &ptr.i_ttu_nb );
901 //fprintf( stderr, "VTS PTR nb: %d\n", ptr.i_ttu_nb );
903 GETL( &ptr.i_ebyte );
904 ptr.pi_ttu_sbyte = malloc( ptr.i_ttu_nb *sizeof(u32) );
905 if( ptr.pi_ttu_sbyte == NULL )
907 intf_ErrMsg( "Out of memory" );
911 for( i=0 ; i<ptr.i_ttu_nb ; i++ )
913 GETL( &ptr.pi_ttu_sbyte[i] );
916 ptr.p_ttu = malloc( ptr.i_ttu_nb *sizeof(ttu_t) );
917 if( ptr.p_ttu == NULL )
919 intf_ErrMsg( "Out of memory" );
923 for( i=0 ; i<ptr.i_ttu_nb ; i++ )
925 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start +
926 ptr.pi_ttu_sbyte[i], SEEK_SET );
927 GETS( &ptr.p_ttu[i].i_pgc_nb );
928 GETS( &ptr.p_ttu[i].i_prg_nb );
929 //fprintf( stderr, "VTS %d PTR Pgc: %d Prg: %d\n", i,ptr.p_ttu[i].i_pgc_nb, ptr.p_ttu[i].i_prg_nb );
935 /*****************************************************************************
936 * ReadVTSTimeMap : Fills the time map table
937 *****************************************************************************/
938 static vts_tmap_ti_t ReadVTSTimeMap( ifo_t* p_ifo )
942 // off_t i_start = p_ifo->i_pos;
944 //fprintf( stderr, "TMAP\n" );
948 GETL( &tmap.i_ebyte );
949 tmap.pi_sbyte = malloc( tmap.i_nb *sizeof(u32) );
950 if( tmap.pi_sbyte == NULL )
952 intf_ErrMsg( "Out of memory" );
956 for( i=0 ; i<tmap.i_nb ; i++ )
958 GETL( &tmap.pi_sbyte[i] );
960 tmap.p_tmap = malloc( tmap.i_nb *sizeof(tmap_t) );
961 if( tmap.p_tmap == NULL )
963 intf_ErrMsg( "Out of memory" );
967 for( i=0 ; i<tmap.i_nb ; i++ )
969 GETC( &tmap.p_tmap[i].i_time_unit );
971 GETS( &tmap.p_tmap[i].i_entry_nb );
972 tmap.p_tmap[i].pi_sector =
973 malloc( tmap.p_tmap[i].i_entry_nb *sizeof(u32) );
974 if( tmap.p_tmap[i].pi_sector == NULL )
976 intf_ErrMsg( "Out of memory" );
980 for( j=0 ; j<tmap.p_tmap[i].i_entry_nb ; j++ )
982 GETL( &tmap.p_tmap[i].pi_sector[j] );
990 /*****************************************************************************
991 * IfoReadVTS : Parse vts*.ifo files to fill the Video Title Set structure.
992 *****************************************************************************/
993 int IfoReadVTS( ifo_t* p_ifo )
999 intf_WarnMsg( 2, "ifo: initializing VTS %d", p_ifo->i_title );
1001 i_title = p_ifo->i_title;
1002 i_off = (off_t)( p_ifo->vmg.ptt_srpt.p_tts[i_title].i_ssector ) *DVD_LB_SIZE
1005 p_ifo->i_pos = lseek( p_ifo->i_fd, i_off, SEEK_SET );
1007 vts.i_pos = p_ifo->i_pos;
1009 vts.mat = ReadVTSInfMat( p_ifo );
1010 if( vts.mat.i_ptt_srpt_ssector )
1012 p_ifo->i_pos = lseek( p_ifo->i_fd, vts.i_pos +
1013 vts.mat.i_ptt_srpt_ssector *DVD_LB_SIZE,
1015 vts.ptt_srpt = ReadVTSTitlePointer( p_ifo );
1017 if( vts.mat.i_m_pgci_ut_ssector )
1019 p_ifo->i_pos = lseek( p_ifo->i_fd, vts.i_pos +
1020 vts.mat.i_m_pgci_ut_ssector *DVD_LB_SIZE,
1022 vts.pgci_ut = ReadUnitTable( p_ifo );
1024 if( vts.mat.i_pgcit_ssector )
1026 p_ifo->i_pos = lseek( p_ifo->i_fd, vts.i_pos +
1027 vts.mat.i_pgcit_ssector *DVD_LB_SIZE,
1029 vts.pgci_ti = ReadUnit( p_ifo );
1031 if( vts.mat.i_tmap_ti_ssector )
1033 p_ifo->i_pos = lseek( p_ifo->i_fd, vts.i_pos +
1034 vts.mat.i_tmap_ti_ssector *DVD_LB_SIZE,
1036 vts.tmap_ti = ReadVTSTimeMap( p_ifo );
1038 if( vts.mat.i_m_c_adt_ssector )
1040 p_ifo->i_pos = lseek( p_ifo->i_fd, vts.i_pos +
1041 vts.mat.i_m_c_adt_ssector *DVD_LB_SIZE,
1043 vts.m_c_adt = ReadCellInf( p_ifo );
1045 if( vts.mat.i_m_vobu_admap_ssector )
1047 p_ifo->i_pos = lseek( p_ifo->i_fd, vts.i_pos +
1048 vts.mat.i_m_vobu_admap_ssector *DVD_LB_SIZE,
1050 vts.m_vobu_admap = ReadMap( p_ifo );
1052 if( vts.mat.i_c_adt_ssector )
1054 p_ifo->i_pos = lseek( p_ifo->i_fd, vts.i_pos +
1055 vts.mat.i_c_adt_ssector *DVD_LB_SIZE,
1057 vts.c_adt = ReadCellInf( p_ifo );
1059 if( vts.mat.i_vobu_admap_ssector )
1061 p_ifo->i_pos = lseek( p_ifo->i_fd, vts.i_pos +
1062 vts.mat.i_vobu_admap_ssector *DVD_LB_SIZE,
1064 vts.vobu_admap = ReadMap( p_ifo );
1073 * DVD Information Management
1076 /*****************************************************************************
1077 * IfoRead : Function that fills structure and calls specified functions
1079 *****************************************************************************/
1080 void IfoRead( ifo_t* p_ifo )
1085 /* Video Title Sets initialization */
1086 p_ifo->p_vts = malloc( p_ifo->vmg.mat.i_tts_nb *sizeof(vts_t) );
1087 if( p_ifo->p_vts == NULL )
1089 intf_ErrMsg( "Out of memory" );
1094 for( i=0 ; i<p_ifo->vmg.mat.i_tts_nb ; i++ )
1097 intf_WarnMsg( 2, "ifo: initializing VTS %d", i+1 );
1099 i_off = (off_t)( p_ifo->vmg.ptt_srpt.p_tts[i].i_ssector ) *DVD_LB_SIZE
1102 p_ifo->i_pos = lseek( p_ifo->i_fd, i_off, SEEK_SET );
1104 /* FIXME : I really don't know why udf find file
1105 * does not give the exact beginning of file */
1107 p_ifo->p_vts[i] = ReadVTS( p_ifo );
1115 * IFO virtual machine : a set of commands that give the
1116 * interactive behaviour of the dvd
1120 #define OP_VAL_16(i) (ntoh16( com.data.pi_16[i]))
1121 #define OP_VAL_8(i) ((com.data.pi_8[i]))
1123 static char ifo_reg[][80]=
1125 "Menu_Language_Code",
1127 "SubPicture_Stream_#",
1133 "Highlighted_Button_#",
1136 "Karaoke_audio_mixing_mode",
1137 "Parental_mgmt_country_code",
1141 "Audio_language_code_setting",
1142 "Audio_language_extension_code",
1143 "SPU_language_code_setting",
1144 "SPU_language_extension_code",
1145 "?Player_Regional_Code",
1151 static char * IfoMath( char val )
1153 static char math_op[][10] =
1173 return (char *) math_op[val & 0x0f];
1177 char ifo_cmp[][10] =
1189 char ifo_parental[][10] =
1201 char ifo_menu_id[][80] =
1213 char * IfoMenuName( char index )
1215 return ifo_menu_id[index&0x07];
1218 static void IfoRegister( u16 i_data, u8 i_direct)
1222 if( 0/*isalpha( i_data >> 8 & 0xff )*/ )
1224 printf("'%c%c'", i_data>>8&0xff, i_data&0xff);
1228 printf("0x%02x", i_data);
1243 printf("s[%s]", ifo_reg[i_data]);
1256 printf("r[0x%02x]", i_data);
1262 static void IfoAdvanced( u8 *pi_code )
1264 u8 i_cmd = pi_code[0];
1270 printf( " Highlight button %d; ", pi_code[1]>>2 );
1275 printf( " Illegal " );
1280 printf( "ReSuME %d", pi_code[7] );
1282 else if( ( i_cmd & 0x06) == 0x02 )
1284 printf ("Link to %s cell ", ( i_cmd & 0x01 ) ? "prev" : "next");
1288 printf( "advanced (0x%02x) ", i_cmd );
1293 static void IfoJmp( ifo_command_t com )
1298 switch( com.i_sub_cmd )
1304 printf( "VTS 0x%02x", OP_VAL_8(3) );
1307 printf( "This VTS Title 0x%02x", OP_VAL_8(3) );
1310 printf( "This VTS Title 0x%02x Part 0x%04x",
1312 OP_VAL_8(0)<<8|OP_VAL_8(1));
1316 printf ("in SystemSpace ");
1317 switch (OP_VAL_8(3)>>4) {
1319 printf ("to play first PGC");
1322 printf ("to menu \"%s\"", decode_menuname (OP_VAL_8(3)));
1326 printf ("to VTS 0x%02x and TTN 0x%02x", OP_VAL_8(1), OP_VAL_8(2));
1329 printf ("to VMGM PGC number 0x%02x", OP_VAL_8(0)<<8 | OP_VAL_8(1));
1332 printf ("vts 0x%02x lu 0x%02x menu \"%s\"", OP_VAL_8(2), OP_VAL_8(1), decode_menuname (OP_VAL_8(3)));
1335 switch( OP_VAL_8(3)>>6 )
1338 printf( "to play first PGC" );
1341 printf( "to VMG title menu (?)" );
1344 printf( "vts 0x%02x lu 0x%02x menu \"%s\"",
1347 IfoMenuName( OP_VAL_8(3)&0xF ) );
1350 printf( "vmg pgc 0x%04x (?)", ( OP_VAL_8(0)<<8) | OP_VAL_8(1) );
1357 switch(OP_VAL_8(3)>>4) {
1359 printf ("system first pgc");
1362 printf ("system title menu");
1365 printf ("system menu \"%s\"", decode_menuname (OP_VAL_8(3)));
1368 printf ("system vmg pgc %02x ????", OP_VAL_8(0)<<8|OP_VAL_8(1));
1371 printf ("system lu 0x%02x menu \"%s\"", OP_VAL_8(2), decode_menuname (OP_VAL_8(3)));
1374 printf ("system vmg pgc 0x%02x", OP_VAL_8(0)<<8|OP_VAL_8(1));
1378 // OP_VAL_8(2) is number of cell
1379 // it is processed BEFORE switch
1380 // under some conditions, it is ignored
1381 // I don't understand exactly what it means
1382 printf( " ( spec cell 0x%02X ) ", OP_VAL_8(2) );
1384 switch( OP_VAL_8(3)>>6 )
1387 printf( "to FP PGC" );
1390 printf( "to VMG root menu (?)" );
1393 printf( "to VTS menu \"%s\" (?)",
1394 IfoMenuName(OP_VAL_8(3)&0xF) );
1397 printf( "vmg pgc 0x%02x (?)", (OP_VAL_8(0)<<8)|OP_VAL_8(1) );
1405 static void IfoLnk( ifo_command_t com )
1407 u16 i_button=OP_VAL_8(4)>>2;
1411 switch( com.i_sub_cmd )
1414 IfoAdvanced( &OP_VAL_8(4) );
1418 printf( "PGC 0x%02x", OP_VAL_16(2) );
1422 printf( "PTT 0x%02x", OP_VAL_16(2) );
1426 printf( "Program 0x%02x this PGC", OP_VAL_8(5) );
1430 printf( "Cell 0x%02x this PGC", OP_VAL_8(5) );
1438 printf( ", Highlight 0x%02x", OP_VAL_8(4)>>2 );
1443 void IfoSetSystem( ifo_command_t com )
1450 for( i=1; i<=3; i++ )
1452 if( OP_VAL_8(i)&0x80 )
1456 printf ("s[%s] = 0x%02x;", ifo_reg[i], OP_VAL_8(i)&0xf);
1460 printf ("s[%s] = r[0x%02x];", ifo_reg[i], OP_VAL_8(i)&0xf);
1466 if(OP_VAL_8(1]&0x80)
1467 printf ("s[%s] = 0x%02x;", reg_name[1], OP_VAL_8(1]&0xf);
1468 if(OP_VAL_8(2)&0x80)
1469 //DENT: lwhat about 0x7f here ???
1470 printf ("s[%s] = 0x%02x;", reg_name[2], OP_VAL_8(2)&0x7f);
1471 if(OP_VAL_8(3)&0x80)
1472 printf ("s[%s] = 0x%02x;", reg_name[3], OP_VAL_8(3)&0xf);
1474 if(OP_VAL_8(1)&0x80)
1475 printf ("s[%s] = r[0x%02x];", reg_name[1], OP_VAL_8(1)&0xf);
1476 if(OP_VAL_8(2)&0x80)
1477 printf ("s[%s] = r[0x%02x];", reg_name[2], OP_VAL_8(2)&0xf);
1478 if(OP_VAL_8(3)&0x80)
1479 printf ("s[%s] = r[0x%02x];", reg_name[3], OP_VAL_8(3)&0xf);
1487 printf( "s[%s] = 0x%02x", ifo_reg[9], OP_VAL_16(0) );
1491 printf( "s[%s] = r[0x%02x]", ifo_reg[9], OP_VAL_8(1)&0x0f );
1494 printf( "s[%s] = (s[%s]&0x7FFF)|0x%02x",
1495 ifo_reg[10], ifo_reg[10], OP_VAL_16(1)&0x8000);
1500 printf( "r[0x%02x] = 0x%02x", OP_VAL_8(3)&0x0f, OP_VAL_16(0) );
1504 printf ("r[r[0x%02x]] = r[0x%02x]",
1505 OP_VAL_8(3)&0x0f, OP_VAL_8(1)&0x0f);
1509 //actually only bits 00011100 00011100 are set
1512 printf ("s[%s] = 0x%02x", ifo_reg[11], OP_VAL_16(1));
1516 printf ("s[%s] = r[0x%02x]", ifo_reg[11], OP_VAL_8(3)&0x0f );
1521 //s[%s]=(r[%s]&0x3FF) | (0x%02x << 0xA);
1522 //but it is way too ugly
1525 printf( "s[%s] = 0x%02x", ifo_reg[8], OP_VAL_8(2)>>2 );
1529 printf( "s[%s] = r[0x%02x]", ifo_reg[8], OP_VAL_8(3)&0x0f );
1537 static void IfoSet( ifo_command_t com )
1539 IfoRegister( OP_VAL_16(0), 0 );
1540 printf( " %s ", IfoMath( com.i_cmd ) );
1541 IfoRegister( OP_VAL_16(1), com.i_direct );
1544 /*****************************************************************************
1545 * CommandRead : translates the command strings in ifo into command
1547 *****************************************************************************/
1548 void CommandRead( ifo_command_t com )
1550 u8* pi_code = (u8*)(&com);
1552 switch( com.i_type )
1565 printf ("if (r[0x%02x] %s ", OP_VAL_8(1)&0x0f,
1566 ifo_cmp[com.i_cmp]);
1567 IfoRegister (OP_VAL_16(1), com.i_dir_cmp);
1572 switch( com.i_sub_cmd )
1575 printf( "goto Line 0x%02x", OP_VAL_16(2) );
1579 printf( "stop VM" );
1583 printf( "Set Parental Level To %s and goto Line 0x%02x",
1584 ifo_parental[OP_VAL_8(4)&0x7],
1589 printf( "Illegal" );
1608 printf( "if (r[0x%02x] %s ", OP_VAL_8(4)&0x0f,
1609 ifo_cmp[com.i_cmp] );
1610 IfoRegister( OP_VAL_8(5), 0 );
1621 printf( "if (r[0x%02x] %s ", OP_VAL_8(1)&0x0f,
1622 ifo_cmp[com.i_cmp] );
1623 IfoRegister( OP_VAL_16(1), com.i_dir_cmp );
1637 IfoSetSystem( com );
1639 else if( com.i_cmp && !com.i_sub_cmd )
1641 printf ("if (r[0x%02x] %s ", OP_VAL_8(4)&0x0f, ifo_cmp[com.i_cmp]);
1642 IfoRegister( OP_VAL_8(5), 0 );
1644 IfoSetSystem( com );
1646 else if( !com.i_cmp && com.i_sub_cmd )
1649 IfoSetSystem( com );
1665 else if( com.i_cmp && !com.i_sub_cmd )
1667 printf ("if (r[0x%02x] %s ", OP_VAL_8(0)&0x0f, ifo_cmp[com.i_cmp]);
1668 IfoRegister( OP_VAL_16(2), com.i_dir_cmp );
1672 else if( !com.i_cmp && com.i_sub_cmd )
1686 * math command on r[opcode[1]] and
1687 * direct?be2me_16(OP_VAL_8(0)):reg[OP_VAL_8(1)] is executed
1688 * ( unless command is swap; then r[opcode[1]] and r[OP_VAL_8(1)]
1690 * boolean operation cmp on r[opcode[1]] and
1691 * dir_cmp?be2me_16(OP_VAL_8(1)[1]):reg[OP_VAL_8(3)] is executed
1692 * on true result, buttons(c[6], c[7]) is called
1693 * problem is 'what is buttons()'
1696 printf( "r[0x%X] ", pi_code[1] );
1697 printf( " %s ", IfoMath( com.i_cmd ) );
1698 if( com.i_cmd == 2 )
1700 printf( "r[0x%X] ", OP_VAL_8(1) );
1704 IfoRegister( OP_VAL_16(0), com.i_direct );
1708 printf( "if ( r[%d] %s ", pi_code[1], ifo_cmp[com.i_cmp] );
1709 IfoRegister( OP_VAL_8(1), com.i_dir_cmp );
1710 printf( " ) then {" );
1711 IfoAdvanced( &OP_VAL_8(4) );
1716 * opposite to case 4: boolean, math and buttons.
1722 if( !com.i_direct && com.i_dir_cmp )
1724 printf( "0x%X", OP_VAL_16(1) );
1728 IfoRegister( OP_VAL_8(3), 0 );
1729 if( OP_VAL_8(3)&0x80 )
1731 printf( "s[%s]", ifo_reg[OP_VAL_8(3)&0x1F] );
1735 printf( "r[0x%X]", OP_VAL_8(3)&0x1F);
1736 // 0x1F is either not a mistake,
1737 // or Microsoft programmer's mistake!!!
1741 printf( " %s r[0x%X] ", ifo_cmp[com.i_cmp],
1742 com.i_direct ? OP_VAL_8(2) : OP_VAL_8(1) );
1743 printf( " ) then {" );
1744 printf( "r[0x%X] ", pi_code[1] & 0xF );
1745 printf( " %s ", IfoMath( com.i_cmd ) );
1747 if( com.i_cmd == 0x02 ) // swap
1749 printf("r[0x%X] ", OP_VAL_8(0)&0x1F);
1755 printf( "0x%X", OP_VAL_16(0) );
1759 if( OP_VAL_8(0) & 0x80 )
1761 printf("s[%s]", ifo_reg[OP_VAL_8(0) & 0x1F] );
1765 printf("r[0x%X]", OP_VAL_8(0) & 0x1F );
1771 IfoAdvanced( &OP_VAL_8(4) );
1777 printf( "Unknown Command\n" );
1784 /*****************************************************************************
1785 * CommandPrint : print in clear text (I hope so !) what a command does
1786 *****************************************************************************/
1787 void CommandPrint( ifo_t ifo )