1 /*****************************************************************************
2 * dvd_ifo.c: Functions for ifo parsing
3 *****************************************************************************
4 * Copyright (C) 1999-2001 VideoLAN
5 * $Id: dvd_ifo.c,v 1.4 2001/02/09 03:51:42 stef Exp $
7 * Author: Stéphane Borel <stef@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
36 #include "input_dvd.h"
38 void CommandRead( ifo_command_t );
44 /*****************************************************************************
45 * IfoFindVMG : When reading directly on a device, finds the offset to the
46 * beginning of video_ts.ifo.
47 *****************************************************************************/
48 static int IfoFindVMG( ifo_t* p_ifo )
50 char psz_ifo_start[12] = "DVDVIDEO-VMG";
53 read( p_ifo->i_fd, psz_test, 12 );
55 while( strncmp( psz_test, psz_ifo_start, 12 ) != 0 )
57 /* The start of ifo file is on a sector boundary */
58 p_ifo->i_pos = lseek( p_ifo->i_fd,
59 p_ifo->i_pos + DVD_LB_SIZE,
61 read( p_ifo->i_fd, psz_test, 12 );
63 p_ifo->i_off = p_ifo->i_pos;
65 //fprintf( stderr, "VMG Off : %lld\n", (long long)(p_ifo->i_off) );
70 /*****************************************************************************
71 * IfoFindVTS : beginning of vts_*.ifo.
72 *****************************************************************************/
73 static int IfoFindVTS( ifo_t* p_ifo )
75 char psz_ifo_start[12] = "DVDVIDEO-VTS";
78 read( p_ifo->i_fd, psz_test, 12 );
80 while( strncmp( psz_test, psz_ifo_start, 12 ) != 0 )
82 /* The start of ifo file is on a sector boundary */
83 p_ifo->i_pos = lseek( p_ifo->i_fd,
84 p_ifo->i_pos + DVD_LB_SIZE,
86 read( p_ifo->i_fd, psz_test, 12 );
88 p_ifo->i_off = p_ifo->i_pos;
90 //fprintf( stderr, "VTS Off : %lld\n", (long long)(p_ifo->i_off) );
95 /*****************************************************************************
96 * IfoInit : Creates an ifo structure and prepares for parsing directly
98 *****************************************************************************/
99 ifo_t IfoInit( int i_fd )
103 /* If we are here the dvd device has already been opened */
105 /* No data at the beginning of the disk
106 * 512000 bytes is just another value :) */
107 ifo.i_pos = lseek( ifo.i_fd, 250 *DVD_LB_SIZE, SEEK_SET );
108 /* FIXME : use udf filesystem to find the beginning of the file */
114 /*****************************************************************************
115 * IfoEnd : Frees all the memory allocated to ifo structures
116 *****************************************************************************/
117 void IfoEnd( ifo_t* p_ifo )
121 /* Free structures from video title sets */
122 for( j=0 ; j<p_ifo->vmg.mat.i_tts_nb ; j++ )
124 free( p_ifo->p_vts[j].vobu_admap.pi_vobu_ssector );
125 free( p_ifo->p_vts[j].c_adt.p_cell_inf );
126 free( p_ifo->p_vts[j].m_vobu_admap.pi_vobu_ssector );
127 free( p_ifo->p_vts[j].m_c_adt.p_cell_inf );
128 for( i=0 ; i<p_ifo->p_vts[j].tmap_ti.i_nb ; i++ )
130 free( p_ifo->p_vts[j].tmap_ti.p_tmap[i].pi_sector );
132 free( p_ifo->p_vts[j].tmap_ti.pi_sbyte );
133 free( p_ifo->p_vts[j].tmap_ti.p_tmap );
134 free( p_ifo->p_vts[j].pgci_ti.p_srp );
135 for( i=0 ; i<p_ifo->p_vts[j].pgci_ut.i_lu_nb ; i++ )
137 free( p_ifo->p_vts[j].pgci_ut.p_pgci_inf[i].p_srp );
139 free( p_ifo->p_vts[j].pgci_ut.p_pgci_inf );
140 free( p_ifo->p_vts[j].pgci_ut.p_lu );
143 free( p_ifo->p_vts );
145 /* Free structures from video manager */
146 free( p_ifo->vmg.vobu_admap.pi_vobu_ssector );
147 free( p_ifo->vmg.c_adt.p_cell_inf );
148 for( i=0 ; i<p_ifo->vmg.pgci_ut.i_lu_nb ; i++ )
150 free( p_ifo->vmg.pgci_ut.p_pgci_inf[i].p_srp );
152 free( p_ifo->vmg.pgci_ut.p_pgci_inf );
153 free( p_ifo->vmg.pgci_ut.p_lu );
154 for( i=1 ; i<=8 ; i++ )
156 free( p_ifo->vmg.ptl_mait.p_ptl_mask->ppi_ptl_mask[i] );
158 free( p_ifo->vmg.ptl_mait.p_ptl_desc );
159 free( p_ifo->vmg.ptl_mait.p_ptl_mask );
160 free( p_ifo->vmg.vts_atrt.pi_vts_atrt_sbyte );
161 free( p_ifo->vmg.vts_atrt.p_vts_atrt );
162 free( p_ifo->vmg.pgc.p_cell_pos_inf );
163 free( p_ifo->vmg.pgc.p_cell_play_inf );
164 free( p_ifo->vmg.pgc.prg_map.pi_entry_cell );
165 free( p_ifo->vmg.pgc.com_tab.p_cell_com );
166 free( p_ifo->vmg.pgc.com_tab.p_post_com );
167 free( p_ifo->vmg.pgc.com_tab.p_pre_com );
173 * Macros to process ifo files
176 #define GET( p_field , i_len ) \
178 read( p_ifo->i_fd , (p_field) , (i_len) ); \
179 /*fprintf(stderr, "Pos : %lld Val : %llx\n", \
180 (long long)(p_ifo->i_pos - i_start), \
181 (long long)*(p_field) ); */ \
182 p_ifo->i_pos += i_len; \
185 #define GETC( p_field ) \
187 read( p_ifo->i_fd , (p_field) , 1 ); \
188 /*fprintf(stderr, "Pos : %lld Value : %d\n", \
189 (long long)(p_ifo->i_pos - i_start), \
194 #define GETS( p_field ) \
196 read( p_ifo->i_fd , (p_field) , 2 ); \
197 *(p_field) = ntohs( *(p_field) ); \
198 /*fprintf(stderr, "Pos : %lld Value : %d\n", \
199 (long long)(p_ifo->i_pos - i_start), \
204 #define GETL( p_field ) \
206 read( p_ifo->i_fd , (p_field) , 4 ); \
207 *(p_field) = ntohl( *(p_field) ); \
208 /*fprintf(stderr, "Pos : %lld Value : %d\n", \
209 (long long)(p_ifo->i_pos - i_start), \
214 #define GETLL( p_field ) \
216 read( p_ifo->i_fd , (p_field) , 8 ); \
217 *(p_field) = ntoh64( *(p_field) ); \
218 /*fprintf(stderr, "Pos : %lld Value : %lld\n", \
219 (long long)(p_ifo->i_pos - i_start), \
224 #define FLUSH( i_len ) \
226 /*fprintf(stderr, "Pos : %lld\n", (long long)(p_ifo->i_pos - i_start));*/ \
227 p_ifo->i_pos = lseek( p_ifo->i_fd , \
228 p_ifo->i_pos + (i_len), SEEK_SET ); \
232 * Function common to Video Manager and Video Title set Processing
235 /*****************************************************************************
236 * ReadPGC : Fills the Program Chain structure.
237 *****************************************************************************/
238 #define GETCOMMAND( p_com ) \
240 read( p_ifo->i_fd , (p_com) , 8 ); \
241 /*fprintf(stderr, "Pos : %lld Type : %d direct : %d cmd : %d dircmp : %d cmp : %d subcmd : %d v0 : %d v2 : %d v4 : %d\n", \
242 (long long)(p_ifo->i_pos - i_start), \
243 (int)((p_com)->i_type), \
244 (int)((p_com)->i_direct), \
245 (int)((p_com)->i_cmd), \
246 (int)((p_com)->i_dir_cmp), \
247 (int)((p_com)->i_cmp), \
248 (int)((p_com)->i_sub_cmd), \
249 (int)((p_com)->data.pi_16[0]), \
250 (int)((p_com)->data.pi_16[1]), \
251 (int)((p_com)->data.pi_16[2]));*/ \
252 /* CommandRead( *(p_com) );*/ \
256 static pgc_t ReadPGC( ifo_t* p_ifo )
260 off_t i_start = p_ifo->i_pos;
262 //fprintf( stderr, "PGC\n" );
265 GETC( &pgc.i_prg_nb );
266 GETC( &pgc.i_cell_nb );
267 GETL( &pgc.i_play_time );
268 GETL( &pgc.i_prohibited_user_op );
269 for( i=0 ; i<8 ; i++ )
271 GETS( &pgc.pi_audio_status[i] );
273 for( i=0 ; i<32 ; i++ )
275 GETL( &pgc.pi_subpic_status[i] );
277 GETS( &pgc.i_next_pgc_nb );
278 GETS( &pgc.i_prev_pgc_nb );
279 GETS( &pgc.i_goup_pgc_nb );
280 GETC( &pgc.i_still_time );
281 GETC( &pgc.i_play_mode );
282 for( i=0 ; i<16 ; i++ )
284 GETL( &pgc.pi_yuv_color[i] );
285 /* FIXME : We have to erase the extra bit */
287 GETS( &pgc.i_com_tab_sbyte );
288 GETS( &pgc.i_prg_map_sbyte );
289 GETS( &pgc.i_cell_play_inf_sbyte );
290 GETS( &pgc.i_cell_pos_inf_sbyte );
292 /* Parsing of pgc_com_tab_t */
293 if( pgc.i_com_tab_sbyte )
295 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start
296 + pgc.i_com_tab_sbyte, SEEK_SET );
297 GETS( &pgc.com_tab.i_pre_com_nb );
298 GETS( &pgc.com_tab.i_post_com_nb );
299 GETS( &pgc.com_tab.i_cell_com_nb );
301 if( pgc.com_tab.i_pre_com_nb )
303 pgc.com_tab.p_pre_com =
304 malloc(pgc.com_tab.i_pre_com_nb *sizeof(ifo_command_t));
305 if( pgc.com_tab.p_pre_com == NULL )
307 intf_ErrMsg( "Out of memory" );
311 for( i=0 ; i<pgc.com_tab.i_pre_com_nb ; i++ )
313 GETCOMMAND( &pgc.com_tab.p_pre_com[i] );
316 if( pgc.com_tab.i_post_com_nb )
318 pgc.com_tab.p_post_com =
319 malloc(pgc.com_tab.i_post_com_nb *sizeof(ifo_command_t));
320 if( pgc.com_tab.p_post_com == NULL )
322 intf_ErrMsg( "Out of memory" );
326 for( i=0 ; i<pgc.com_tab.i_post_com_nb ; i++ )
328 GETCOMMAND( &pgc.com_tab.p_post_com[i] );
331 if( pgc.com_tab.i_cell_com_nb )
333 pgc.com_tab.p_cell_com =
334 malloc(pgc.com_tab.i_cell_com_nb *sizeof(ifo_command_t));
335 if( pgc.com_tab.p_cell_com == NULL )
337 intf_ErrMsg( "Out of memory" );
341 for( i=0 ; i<pgc.com_tab.i_cell_com_nb ; i++ )
343 GETCOMMAND( &pgc.com_tab.p_cell_com[i] );
347 /* Parsing of pgc_prg_map_t */
348 if( pgc.i_prg_map_sbyte )
350 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start
351 + pgc.i_prg_map_sbyte, SEEK_SET );
352 pgc.prg_map.pi_entry_cell = malloc( pgc.i_prg_nb *sizeof(u8) );
353 if( pgc.prg_map.pi_entry_cell == NULL )
355 intf_ErrMsg( "Out of memory" );
359 GET( pgc.prg_map.pi_entry_cell, pgc.i_prg_nb );
360 /* FIXME : check endianness here */
362 /* Parsing of cell_play_inf_t */
363 if( pgc.i_cell_play_inf_sbyte )
365 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start
366 + pgc.i_cell_play_inf_sbyte, SEEK_SET );
367 pgc.p_cell_play_inf = malloc( pgc.i_cell_nb *sizeof(cell_play_inf_t) );
368 if( pgc.p_cell_play_inf == NULL )
370 intf_ErrMsg( "Out of memory" );
374 for( i=0 ; i<pgc.i_cell_nb ; i++ )
376 GETS( &pgc.p_cell_play_inf[i].i_cat );
377 GETC( &pgc.p_cell_play_inf[i].i_still_time );
378 GETC( &pgc.p_cell_play_inf[i].i_com_nb );
379 GETL( &pgc.p_cell_play_inf[i].i_play_time );
380 GETL( &pgc.p_cell_play_inf[i].i_entry_sector );
381 GETL( &pgc.p_cell_play_inf[i].i_first_ilvu_vobu_esector );
382 GETL( &pgc.p_cell_play_inf[i].i_lvobu_ssector );
383 GETL( &pgc.p_cell_play_inf[i].i_lsector );
386 /* Parsing of cell_pos_inf_map */
387 if( pgc.i_cell_pos_inf_sbyte )
389 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start
390 + pgc.i_cell_pos_inf_sbyte, SEEK_SET );
391 pgc.p_cell_pos_inf = malloc( pgc.i_cell_nb *sizeof(cell_pos_inf_t) );
392 if( pgc.p_cell_play_inf == NULL )
394 intf_ErrMsg( "Out of memory" );
398 for( i=0 ; i<pgc.i_cell_nb ; i++ )
400 GETS( &pgc.p_cell_pos_inf[i].i_vob_id );
402 GETC( &pgc.p_cell_pos_inf[i].i_cell_id );
409 /*****************************************************************************
410 * ReadUnit : Fills Menu Language Unit Table/ PGC Info Table
411 *****************************************************************************/
412 static pgci_inf_t ReadUnit( ifo_t* p_ifo )
416 off_t i_start = p_ifo->i_pos;
418 //fprintf( stderr, "Unit\n" );
420 GETS( &inf.i_srp_nb );
422 GETL( &inf.i_lu_ebyte );
423 inf.p_srp = malloc( inf.i_srp_nb *sizeof(pgci_srp_t) );
424 if( inf.p_srp == NULL )
426 intf_ErrMsg( "Out of memory" );
430 for( i=0 ; i<inf.i_srp_nb ; i++ )
432 GETC( &inf.p_srp[i].i_pgc_cat_mask );
433 GETC( &inf.p_srp[i].i_pgc_cat );
434 GETS( &inf.p_srp[i].i_par_mask );
435 GETL( &inf.p_srp[i].i_pgci_sbyte );
437 for( i=0 ; i<inf.i_srp_nb ; i++ )
439 p_ifo->i_pos = lseek( p_ifo->i_fd,
440 i_start + inf.p_srp[i].i_pgci_sbyte,
442 inf.p_srp[i].pgc = ReadPGC( p_ifo );
448 /*****************************************************************************
449 * ReadUnitTable : Fills the PGCI Unit structure.
450 *****************************************************************************/
451 static pgci_ut_t ReadUnitTable( ifo_t* p_ifo )
455 off_t i_start = p_ifo->i_pos;
457 //fprintf( stderr, "Unit Table\n" );
459 GETS( &pgci.i_lu_nb );
461 GETL( &pgci.i_ebyte );
462 pgci.p_lu = malloc( pgci.i_lu_nb *sizeof(pgci_lu_t) );
463 if( pgci.p_lu == NULL )
465 intf_ErrMsg( "Out of memory" );
469 for( i=0 ; i<pgci.i_lu_nb ; i++ )
471 GET( pgci.p_lu[i].ps_lang_code, 2 );
473 GETC( &pgci.p_lu[i].i_existence_mask );
474 GETL( &pgci.p_lu[i].i_lu_sbyte );
476 pgci.p_pgci_inf = malloc( pgci.i_lu_nb *sizeof(pgci_inf_t) );
477 if( pgci.p_pgci_inf == NULL )
479 intf_ErrMsg( "Out of memory" );
483 for( i=0 ; i<pgci.i_lu_nb ; i++ )
485 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start +
486 pgci.p_lu[i].i_lu_sbyte,
488 pgci.p_pgci_inf[i] = ReadUnit( p_ifo );
494 /*****************************************************************************
495 * ReadCellInf : Fills the Cell Information structure.
496 *****************************************************************************/
497 static c_adt_t ReadCellInf( ifo_t* p_ifo )
501 off_t i_start = p_ifo->i_pos;
503 //fprintf( stderr, "CELL ADD\n" );
505 GETS( &c_adt.i_vob_nb );
507 GETL( &c_adt.i_ebyte );
508 i_max = ( i_start + c_adt.i_ebyte + 1 - p_ifo->i_pos ) / sizeof(cell_inf_t);
509 c_adt.p_cell_inf = malloc( i_max *sizeof(cell_inf_t) );
510 if( c_adt.p_cell_inf == NULL )
512 intf_ErrMsg( "Out of memory" );
516 for( i=0 ; i<i_max ; i++ )
518 GETS( &c_adt.p_cell_inf[i].i_vob_id );
519 GETC( &c_adt.p_cell_inf[i].i_cell_id );
521 GETL( &c_adt.p_cell_inf[i].i_ssector );
522 GETL( &c_adt.p_cell_inf[i].i_esector );
528 /*****************************************************************************
529 * ReadMap : Fills the VOBU Map structure.
530 *****************************************************************************/
531 static vobu_admap_t ReadMap( ifo_t* p_ifo )
535 off_t i_start = p_ifo->i_pos;
537 //fprintf( stderr, "VOBU ADMAP\n" );
539 GETL( &map.i_ebyte );
540 i_max = ( i_start + map.i_ebyte + 1 - p_ifo->i_pos ) / sizeof(u32);
541 map.pi_vobu_ssector = malloc( i_max *sizeof(u32) );
542 for( i=0 ; i<i_max ; i++ )
544 GETL( &map.pi_vobu_ssector[i] );
551 * Video Manager Information Processing.
552 * This is what is contained in video_ts.ifo.
555 /*****************************************************************************
556 * ReadVMGInfMat : Fills the Management Information structure.
557 *****************************************************************************/
558 static vmgi_mat_t ReadVMGInfMat( ifo_t* p_ifo )
562 // off_t i_start = p_ifo->i_pos;
564 //fprintf( stderr, "VMGI\n" );
566 GET( mat.psz_id , 12 );
567 mat.psz_id[12] = '\0';
568 GETL( &mat.i_lsector );
570 GETL( &mat.i_i_lsector );
572 GETC( &mat.i_spec_ver );
574 GETS( &mat.i_vol_nb );
576 GETC( &mat.i_disc_side );
578 GETS( &mat.i_tts_nb );
579 GET( mat.ps_provider_id, 32 );
580 GETLL( &mat.i_pos_code );
582 GETL( &mat.i_i_mat_ebyte );
583 GETL( &mat.i_fp_pgc_sbyte );
585 GETL( &mat.i_vobs_ssector );
586 GETL( &mat.i_ptt_srpt_ssector );
587 GETL( &mat.i_pgci_ut_ssector );
588 GETL( &mat.i_ptl_mait_ssector );
589 GETL( &mat.i_vts_atrt_ssector );
590 GETL( &mat.i_txtdt_mg_ssector );
591 GETL( &mat.i_c_adt_ssector );
592 GETL( &mat.i_vobu_admap_ssector );
594 GETS( &mat.i_video_atrt );
596 GETC( &mat.i_audio_nb );
597 //fprintf( stderr, "vmgi audio nb : %d\n", mat.i_audio_nb );
598 for( i=0 ; i < 8 ; i++ )
600 GETLL( &mat.pi_audio_atrt[i] );
603 GETC( &mat.i_subpic_nb );
604 //fprintf( stderr, "vmgi subpic nb : %d\n", mat.i_subpic_nb );
605 for( i=0 ; i < mat.i_subpic_nb ; i++ )
607 GET( &mat.pi_subpic_atrt[i], 6 );
608 /* FIXME : take care of endianness */
614 /*****************************************************************************
615 * ReadVMGTitlePointer : Fills the Part Of Title Search Pointer structure.
616 *****************************************************************************/
617 static vmg_ptt_srpt_t ReadVMGTitlePointer( ifo_t* p_ifo )
621 // off_t i_start = p_ifo->i_pos;
623 //fprintf( stderr, "PTR\n" );
625 GETS( &ptr.i_ttu_nb );
627 GETL( &ptr.i_ebyte );
629 ptr.p_tts = malloc( ptr.i_ttu_nb *sizeof(tts_t) );
630 if( ptr.p_tts == NULL )
632 intf_ErrMsg( "Out of memory" );
636 for( i=0 ; i<ptr.i_ttu_nb ; i++ )
638 GETC( &ptr.p_tts[i].i_play_type );
639 GETC( &ptr.p_tts[i].i_angle_nb );
640 GETS( &ptr.p_tts[i].i_ptt_nb );
641 GETS( &ptr.p_tts[i].i_parental_id );
642 GETC( &ptr.p_tts[i].i_tts_nb );
643 GETC( &ptr.p_tts[i].i_vts_ttn );
644 GETL( &ptr.p_tts[i].i_ssector );
650 /*****************************************************************************
651 * ReadParentalInf : Fills the Parental Management structure.
652 *****************************************************************************/
653 static vmg_ptl_mait_t ReadParentalInf( ifo_t* p_ifo )
657 off_t i_start = p_ifo->i_pos;
659 //fprintf( stderr, "PTL\n" );
661 GETS( &par.i_country_nb );
662 GETS( &par.i_vts_nb );
663 GETL( &par.i_ebyte );
664 par.p_ptl_desc = malloc( par.i_country_nb *sizeof(vmg_ptl_mai_desc_t) );
665 if( par.p_ptl_desc == NULL )
667 intf_ErrMsg( "Out of memory" );
671 for( i=0 ; i<par.i_country_nb ; i++ )
673 GET( par.p_ptl_desc[i].ps_country_code, 2 );
675 GETS( &par.p_ptl_desc[i].i_ptl_mai_sbyte );
678 par.p_ptl_mask = malloc( par.i_country_nb *sizeof(vmg_ptl_mask_t) );
679 if( par.p_ptl_mask == NULL )
681 intf_ErrMsg( "Out of memory" );
685 for( i=0 ; i<par.i_country_nb ; i++ )
687 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start +
688 par.p_ptl_desc[i].i_ptl_mai_sbyte, SEEK_SET );
689 for( j=1 ; j<=8 ; j++ )
691 par.p_ptl_mask[i].ppi_ptl_mask[j] =
692 malloc( par.i_vts_nb *sizeof(u16) );
693 if( par.p_ptl_mask[i].ppi_ptl_mask[j] == NULL )
695 intf_ErrMsg( "Out of memory" );
699 for( k=0 ; k<par.i_vts_nb ; k++ )
701 GETS( &par.p_ptl_mask[i].ppi_ptl_mask[j][k] );
709 /*****************************************************************************
710 * ReadVTSAttr : Fills the structure about VTS attributes.
711 *****************************************************************************/
712 static vmg_vts_atrt_t ReadVTSAttr( ifo_t* p_ifo )
716 off_t i_start = p_ifo->i_pos;
718 //fprintf( stderr, "VTS ATTR\n" );
720 GETS( &atrt.i_vts_nb );
722 GETL( &atrt.i_ebyte );
723 atrt.pi_vts_atrt_sbyte = malloc( atrt.i_vts_nb *sizeof(u32) );
724 if( atrt.pi_vts_atrt_sbyte == NULL )
726 intf_ErrMsg( "Out of memory" );
730 for( i=0 ; i<atrt.i_vts_nb ; i++ )
732 GETL( &atrt.pi_vts_atrt_sbyte[i] );
734 atrt.p_vts_atrt = malloc( atrt.i_vts_nb *sizeof(vts_atrt_t) );
735 if( atrt.p_vts_atrt == NULL )
737 intf_ErrMsg( "Out of memory" );
741 for( i=0 ; i<atrt.i_vts_nb ; i++ )
743 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start +
744 atrt.pi_vts_atrt_sbyte[i],
746 GETL( &atrt.p_vts_atrt[i].i_ebyte );
747 GETL( &atrt.p_vts_atrt[i].i_cat_app_type );
748 GETS( &atrt.p_vts_atrt[i].i_vtsm_video_atrt );
750 GETC( &atrt.p_vts_atrt[i].i_vtsm_audio_nb );
751 //fprintf( stderr, "m audio nb : %d\n", atrt.p_vts_atrt[i].i_vtsm_audio_nb );
752 for( j=0 ; j<8 ; j++ )
754 GETLL( &atrt.p_vts_atrt[i].pi_vtsm_audio_atrt[j] );
757 GETC( &atrt.p_vts_atrt[i].i_vtsm_subpic_nb );
758 //fprintf( stderr, "m subp nb : %d\n", atrt.p_vts_atrt[i].i_vtsm_subpic_nb );
759 for( j=0 ; j<28 ; j++ )
761 GET( &atrt.p_vts_atrt[i].pi_vtsm_subpic_atrt[j], 6 );
762 /* FIXME : Fix endianness issue here */
765 GETS( &atrt.p_vts_atrt[i].i_vtstt_video_atrt );
767 GETL( &atrt.p_vts_atrt[i].i_vtstt_audio_nb );
768 //fprintf( stderr, "tt audio nb : %d\n", atrt.p_vts_atrt[i].i_vtstt_audio_nb );
769 for( j=0 ; j<8 ; j++ )
771 GETLL( &atrt.p_vts_atrt[i].pi_vtstt_audio_atrt[j] );
774 GETC( &atrt.p_vts_atrt[i].i_vtstt_subpic_nb );
775 //fprintf( stderr, "tt subp nb : %d\n", atrt.p_vts_atrt[i].i_vtstt_subpic_nb );
776 for( j=0 ; j<28/*atrt.p_vts_atrt[i].i_vtstt_subpic_nb*/ ; j++ )
778 GET( &atrt.p_vts_atrt[i].pi_vtstt_subpic_atrt[j], 6 );
779 /* FIXME : Fix endianness issue here */
786 /*****************************************************************************
787 * ReadVMG : Parse video_ts.ifo file to fill the Video Manager structure.
788 *****************************************************************************/
789 static vmg_t ReadVMG( ifo_t* p_ifo )
793 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off, SEEK_SET);
794 vmg.mat = ReadVMGInfMat( p_ifo );
795 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
796 vmg.mat.i_fp_pgc_sbyte, SEEK_SET );
797 vmg.pgc = ReadPGC( p_ifo );
798 if( vmg.mat.i_ptt_srpt_ssector )
800 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
801 vmg.mat.i_ptt_srpt_ssector *DVD_LB_SIZE,
803 vmg.ptt_srpt = ReadVMGTitlePointer( p_ifo );
805 if( vmg.mat.i_pgci_ut_ssector )
807 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
808 vmg.mat.i_pgci_ut_ssector *DVD_LB_SIZE,
810 vmg.pgci_ut = ReadUnitTable( p_ifo );
812 if( vmg.mat.i_ptl_mait_ssector )
814 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
815 vmg.mat.i_ptl_mait_ssector *DVD_LB_SIZE,
817 vmg.ptl_mait = ReadParentalInf( p_ifo );
819 if( vmg.mat.i_vts_atrt_ssector )
821 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
822 vmg.mat.i_vts_atrt_ssector *DVD_LB_SIZE,
824 vmg.vts_atrt = ReadVTSAttr( p_ifo );
826 if( vmg.mat.i_c_adt_ssector )
828 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
829 vmg.mat.i_c_adt_ssector *DVD_LB_SIZE,
831 vmg.c_adt = ReadCellInf( p_ifo );
833 if( vmg.mat.i_vobu_admap_ssector )
835 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
836 vmg.mat.i_vobu_admap_ssector *DVD_LB_SIZE,
838 vmg.vobu_admap = ReadMap( p_ifo );
844 * Video Title Set Information Processing.
845 * This is what is contained in vts_*.ifo.
848 /*****************************************************************************
849 * ReadVTSInfMat : Fills the Title Set Information structure.
850 *****************************************************************************/
851 static vtsi_mat_t ReadVTSInfMat( ifo_t* p_ifo )
855 // off_t i_start = p_ifo->i_pos;
857 //fprintf( stderr, "VTSI\n" );
859 GET( mat.psz_id , 12 );
860 mat.psz_id[12] = '\0';
861 GETL( &mat.i_lsector );
863 GETL( &mat.i_i_lsector );
865 GETC( &mat.i_spec_ver );
868 GETL( &mat.i_mat_ebyte );
870 GETL( &mat.i_m_vobs_ssector );
871 GETL( &mat.i_tt_vobs_ssector );
872 GETL( &mat.i_ptt_srpt_ssector );
873 GETL( &mat.i_pgcit_ssector );
874 GETL( &mat.i_m_pgci_ut_ssector );
875 GETL( &mat.i_tmap_ti_ssector );
876 GETL( &mat.i_m_c_adt_ssector );
877 GETL( &mat.i_m_vobu_admap_ssector );
878 GETL( &mat.i_c_adt_ssector );
879 GETL( &mat.i_vobu_admap_ssector );
881 GETS( &mat.i_m_video_atrt );
883 GETC( &mat.i_m_audio_nb );
884 for( i=0 ; i<8 ; i++ )
886 GETLL( &mat.pi_m_audio_atrt[i] );
889 GETC( &mat.i_m_subpic_nb );
890 for( i=0 ; i<28 ; i++ )
892 GET( &mat.pi_m_subpic_atrt[i], 6 );
893 /* FIXME : take care of endianness */
896 GETS( &mat.i_video_atrt );
898 GETC( &mat.i_audio_nb );
899 //fprintf( stderr, "vtsi audio nb : %d\n", mat.i_audio_nb );
900 for( i=0 ; i<8 ; i++ )
902 GETLL( &mat.pi_audio_atrt[i] );
905 GETC( &mat.i_subpic_nb );
906 //fprintf( stderr, "vtsi subpic nb : %d\n", mat.i_subpic_nb );
907 for( i=0 ; i<mat.i_subpic_nb ; i++ )
909 GET( &mat.pi_subpic_atrt[i], 6 );
910 /* FIXME : take care of endianness */
916 /*****************************************************************************
917 * ReadVTSTitlePointer : Fills the Part Of Title Search Pointer structure.
918 *****************************************************************************/
919 static vts_ptt_srpt_t ReadVTSTitlePointer( ifo_t* p_ifo )
923 off_t i_start = p_ifo->i_pos;
925 //fprintf( stderr, "PTR\n" );
927 GETS( &ptr.i_ttu_nb );
929 GETL( &ptr.i_ebyte );
930 ptr.pi_ttu_sbyte = malloc( ptr.i_ttu_nb *sizeof(u32) );
931 if( ptr.pi_ttu_sbyte == NULL )
933 intf_ErrMsg( "Out of memory" );
937 for( i=0 ; i<ptr.i_ttu_nb ; i++ )
939 GETL( &ptr.pi_ttu_sbyte[i] );
942 ptr.p_ttu = malloc( ptr.i_ttu_nb *sizeof(ttu_t) );
943 if( ptr.p_ttu == NULL )
945 intf_ErrMsg( "Out of memory" );
949 for( i=0 ; i<ptr.i_ttu_nb ; i++ )
951 p_ifo->i_pos = lseek( p_ifo->i_fd, i_start +
952 ptr.pi_ttu_sbyte[i], SEEK_SET );
953 GETS( &ptr.p_ttu[i].i_pgc_nb );
954 GETS( &ptr.p_ttu[i].i_prg_nb );
960 /*****************************************************************************
961 * ReadVTSTimeMap : Fills the time map table
962 *****************************************************************************/
963 static vts_tmap_ti_t ReadVTSTimeMap( ifo_t* p_ifo )
967 // off_t i_start = p_ifo->i_pos;
969 //fprintf( stderr, "TMAP\n" );
973 GETL( &tmap.i_ebyte );
974 tmap.pi_sbyte = malloc( tmap.i_nb *sizeof(u32) );
975 if( tmap.pi_sbyte == NULL )
977 intf_ErrMsg( "Out of memory" );
981 for( i=0 ; i<tmap.i_nb ; i++ )
983 GETL( &tmap.pi_sbyte[i] );
985 tmap.p_tmap = malloc( tmap.i_nb *sizeof(tmap_t) );
986 if( tmap.p_tmap == NULL )
988 intf_ErrMsg( "Out of memory" );
992 for( i=0 ; i<tmap.i_nb ; i++ )
994 GETC( &tmap.p_tmap[i].i_time_unit );
996 GETS( &tmap.p_tmap[i].i_entry_nb );
997 tmap.p_tmap[i].pi_sector =
998 malloc( tmap.p_tmap[i].i_entry_nb *sizeof(u32) );
999 if( tmap.p_tmap[i].pi_sector == NULL )
1001 intf_ErrMsg( "Out of memory" );
1005 for( j=0 ; j<tmap.p_tmap[i].i_entry_nb ; j++ )
1007 GETL( &tmap.p_tmap[i].pi_sector[j] );
1015 /*****************************************************************************
1016 * ReadVTS : Parse vts*.ifo files to fill the Video Title Set structure.
1017 *****************************************************************************/
1018 static vts_t ReadVTS( ifo_t* p_ifo )
1022 vts.i_pos = p_ifo->i_pos;
1024 vts.mat = ReadVTSInfMat( p_ifo );
1025 if( vts.mat.i_ptt_srpt_ssector )
1027 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
1028 vts.mat.i_ptt_srpt_ssector *DVD_LB_SIZE,
1030 vts.ptt_srpt = ReadVTSTitlePointer( p_ifo );
1032 if( vts.mat.i_m_pgci_ut_ssector )
1034 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
1035 vts.mat.i_m_pgci_ut_ssector *DVD_LB_SIZE,
1037 vts.pgci_ut = ReadUnitTable( p_ifo );
1039 if( vts.mat.i_pgcit_ssector )
1041 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
1042 vts.mat.i_pgcit_ssector *DVD_LB_SIZE,
1044 vts.pgci_ti = ReadUnit( p_ifo );
1046 if( vts.mat.i_tmap_ti_ssector )
1048 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
1049 vts.mat.i_tmap_ti_ssector *DVD_LB_SIZE,
1051 vts.tmap_ti = ReadVTSTimeMap( p_ifo );
1053 if( vts.mat.i_m_c_adt_ssector )
1055 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
1056 vts.mat.i_m_c_adt_ssector *DVD_LB_SIZE,
1058 vts.m_c_adt = ReadCellInf( p_ifo );
1060 if( vts.mat.i_m_vobu_admap_ssector )
1062 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
1063 vts.mat.i_m_vobu_admap_ssector *DVD_LB_SIZE,
1065 vts.m_vobu_admap = ReadMap( p_ifo );
1067 if( vts.mat.i_c_adt_ssector )
1069 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
1070 vts.mat.i_c_adt_ssector *DVD_LB_SIZE,
1072 vts.c_adt = ReadCellInf( p_ifo );
1074 if( vts.mat.i_vobu_admap_ssector )
1076 p_ifo->i_pos = lseek( p_ifo->i_fd, p_ifo->i_off +
1077 vts.mat.i_vobu_admap_ssector *DVD_LB_SIZE,
1079 vts.vobu_admap = ReadMap( p_ifo );
1086 * DVD Information Management
1089 /*****************************************************************************
1090 * IfoRead : Function that fills structure and calls specified functions
1092 *****************************************************************************/
1093 void IfoRead( ifo_t* p_ifo )
1098 p_ifo->vmg = ReadVMG( p_ifo );
1099 p_ifo->p_vts = malloc( p_ifo->vmg.mat.i_tts_nb *sizeof(vts_t) );
1100 if( p_ifo->p_vts == NULL )
1102 intf_ErrMsg( "Out of memory" );
1106 for( i=0 ; i<1/*p_ifo->vmg.mat.i_tts_nb*/ ; i++ )
1109 intf_WarnMsg( 3, "######### VTS %d #############\n", i+1 );
1111 i_off = p_ifo->vmg.ptt_srpt.p_tts[i].i_ssector *DVD_LB_SIZE;
1112 p_ifo->i_pos = lseek( p_ifo->i_fd, i_off, SEEK_SET );
1113 /* FIXME : use udf filesystem to avoid this */
1114 IfoFindVTS( p_ifo );
1115 p_ifo->p_vts[i] = ReadVTS( p_ifo );
1121 * IFO virtual machine : a set of commands that give the
1122 * interactive behaviour of the dvd
1126 #define OP_VAL_16(i) (ntoh16( com.data.pi_16[i]))
1127 #define OP_VAL_8(i) ((com.data.pi_8[i]))
1129 static char ifo_reg[][80]=
1131 "Menu_Language_Code",
1133 "SubPicture_Stream_#",
1139 "Highlighted_Button_#",
1142 "Karaoke_audio_mixing_mode",
1143 "Parental_mgmt_country_code",
1147 "Audio_language_code_setting",
1148 "Audio_language_extension_code",
1149 "SPU_language_code_setting",
1150 "SPU_language_extension_code",
1151 "?Player_Regional_Code",
1157 static char * IfoMath( char val )
1159 static char math_op[][10] =
1179 return (char *) math_op[val & 0x0f];
1183 char ifo_cmp[][10] =
1195 char ifo_parental[][10] =
1207 char ifo_menu_id[][80] =
1219 char * IfoMenuName( char index )
1221 return ifo_menu_id[index&0x07];
1224 static void IfoRegister( u16 i_data, u8 i_direct)
1228 if( 0/*isalpha( i_data >> 8 & 0xff )*/ )
1230 printf("'%c%c'", i_data>>8&0xff, i_data&0xff);
1234 printf("0x%02x", i_data);
1249 printf("s[%s]", ifo_reg[i_data]);
1262 printf("r[0x%02x]", i_data);
1268 static void IfoAdvanced( u8 *pi_code )
1270 u8 i_cmd = pi_code[0];
1276 printf( " Highlight button %d; ", pi_code[1]>>2 );
1281 printf( " Illegal " );
1286 printf( "ReSuME %d", pi_code[7] );
1288 else if( ( i_cmd & 0x06) == 0x02 )
1290 printf ("Link to %s cell ", ( i_cmd & 0x01 ) ? "prev" : "next");
1294 printf( "advanced (0x%02x) ", i_cmd );
1299 static void IfoJmp( ifo_command_t com )
1304 switch( com.i_sub_cmd )
1310 printf( "VTS 0x%02x", OP_VAL_8(3) );
1313 printf( "This VTS Title 0x%02x", OP_VAL_8(3) );
1316 printf( "This VTS Title 0x%02x Part 0x%04x",
1318 OP_VAL_8(0)<<8|OP_VAL_8(1));
1322 printf ("in SystemSpace ");
1323 switch (OP_VAL_8(3)>>4) {
1325 printf ("to play first PGC");
1328 printf ("to menu \"%s\"", decode_menuname (OP_VAL_8(3)));
1332 printf ("to VTS 0x%02x and TTN 0x%02x", OP_VAL_8(1), OP_VAL_8(2));
1335 printf ("to VMGM PGC number 0x%02x", OP_VAL_8(0)<<8 | OP_VAL_8(1));
1338 printf ("vts 0x%02x lu 0x%02x menu \"%s\"", OP_VAL_8(2), OP_VAL_8(1), decode_menuname (OP_VAL_8(3)));
1341 switch( OP_VAL_8(3)>>6 )
1344 printf( "to play first PGC" );
1347 printf( "to VMG title menu (?)" );
1350 printf( "vts 0x%02x lu 0x%02x menu \"%s\"",
1353 IfoMenuName( OP_VAL_8(3)&0xF ) );
1356 printf( "vmg pgc 0x%04x (?)", ( OP_VAL_8(0)<<8) | OP_VAL_8(1) );
1363 switch(OP_VAL_8(3)>>4) {
1365 printf ("system first pgc");
1368 printf ("system title menu");
1371 printf ("system menu \"%s\"", decode_menuname (OP_VAL_8(3)));
1374 printf ("system vmg pgc %02x ????", OP_VAL_8(0)<<8|OP_VAL_8(1));
1377 printf ("system lu 0x%02x menu \"%s\"", OP_VAL_8(2), decode_menuname (OP_VAL_8(3)));
1380 printf ("system vmg pgc 0x%02x", OP_VAL_8(0)<<8|OP_VAL_8(1));
1384 // OP_VAL_8(2) is number of cell
1385 // it is processed BEFORE switch
1386 // under some conditions, it is ignored
1387 // I don't understand exactly what it means
1388 printf( " ( spec cell 0x%02X ) ", OP_VAL_8(2) );
1390 switch( OP_VAL_8(3)>>6 )
1393 printf( "to FP PGC" );
1396 printf( "to VMG root menu (?)" );
1399 printf( "to VTS menu \"%s\" (?)",
1400 IfoMenuName(OP_VAL_8(3)&0xF) );
1403 printf( "vmg pgc 0x%02x (?)", (OP_VAL_8(0)<<8)|OP_VAL_8(1) );
1411 static void IfoLnk( ifo_command_t com )
1413 u16 i_button=OP_VAL_8(4)>>2;
1417 switch( com.i_sub_cmd )
1420 IfoAdvanced( &OP_VAL_8(4) );
1424 printf( "PGC 0x%02x", OP_VAL_16(2) );
1428 printf( "PTT 0x%02x", OP_VAL_16(2) );
1432 printf( "Program 0x%02x this PGC", OP_VAL_8(5) );
1436 printf( "Cell 0x%02x this PGC", OP_VAL_8(5) );
1444 printf( ", Highlight 0x%02x", OP_VAL_8(4)>>2 );
1449 void IfoSetSystem( ifo_command_t com )
1456 for( i=1; i<=3; i++ )
1458 if( OP_VAL_8(i)&0x80 )
1462 printf ("s[%s] = 0x%02x;", ifo_reg[i], OP_VAL_8(i)&0xf);
1466 printf ("s[%s] = r[0x%02x];", ifo_reg[i], OP_VAL_8(i)&0xf);
1472 if(OP_VAL_8(1]&0x80)
1473 printf ("s[%s] = 0x%02x;", reg_name[1], OP_VAL_8(1]&0xf);
1474 if(OP_VAL_8(2)&0x80)
1475 //DENT: lwhat about 0x7f here ???
1476 printf ("s[%s] = 0x%02x;", reg_name[2], OP_VAL_8(2)&0x7f);
1477 if(OP_VAL_8(3)&0x80)
1478 printf ("s[%s] = 0x%02x;", reg_name[3], OP_VAL_8(3)&0xf);
1480 if(OP_VAL_8(1)&0x80)
1481 printf ("s[%s] = r[0x%02x];", reg_name[1], OP_VAL_8(1)&0xf);
1482 if(OP_VAL_8(2)&0x80)
1483 printf ("s[%s] = r[0x%02x];", reg_name[2], OP_VAL_8(2)&0xf);
1484 if(OP_VAL_8(3)&0x80)
1485 printf ("s[%s] = r[0x%02x];", reg_name[3], OP_VAL_8(3)&0xf);
1493 printf( "s[%s] = 0x%02x", ifo_reg[9], OP_VAL_16(0) );
1497 printf( "s[%s] = r[0x%02x]", ifo_reg[9], OP_VAL_8(1)&0x0f );
1500 printf( "s[%s] = (s[%s]&0x7FFF)|0x%02x",
1501 ifo_reg[10], ifo_reg[10], OP_VAL_16(1)&0x8000);
1506 printf( "r[0x%02x] = 0x%02x", OP_VAL_8(3)&0x0f, OP_VAL_16(0) );
1510 printf ("r[r[0x%02x]] = r[0x%02x]",
1511 OP_VAL_8(3)&0x0f, OP_VAL_8(1)&0x0f);
1515 //actually only bits 00011100 00011100 are set
1518 printf ("s[%s] = 0x%02x", ifo_reg[11], OP_VAL_16(1));
1522 printf ("s[%s] = r[0x%02x]", ifo_reg[11], OP_VAL_8(3)&0x0f );
1527 //s[%s]=(r[%s]&0x3FF) | (0x%02x << 0xA);
1528 //but it is way too ugly
1531 printf( "s[%s] = 0x%02x", ifo_reg[8], OP_VAL_8(2)>>2 );
1535 printf( "s[%s] = r[0x%02x]", ifo_reg[8], OP_VAL_8(3)&0x0f );
1543 static void IfoSet( ifo_command_t com )
1545 IfoRegister( OP_VAL_16(0), 0 );
1546 printf( " %s ", IfoMath( com.i_cmd ) );
1547 IfoRegister( OP_VAL_16(1), com.i_direct );
1550 /*****************************************************************************
1551 * CommandRead : translates the command strings in ifo into command
1553 *****************************************************************************/
1554 void CommandRead( ifo_command_t com )
1556 u8* pi_code = (u8*)(&com);
1558 switch( com.i_type )
1571 printf ("if (r[0x%02x] %s ", OP_VAL_8(1)&0x0f,
1572 ifo_cmp[com.i_cmp]);
1573 IfoRegister (OP_VAL_16(1), com.i_dir_cmp);
1578 switch( com.i_sub_cmd )
1581 printf( "goto Line 0x%02x", OP_VAL_16(2) );
1585 printf( "stop VM" );
1589 printf( "Set Parental Level To %s and goto Line 0x%02x",
1590 ifo_parental[OP_VAL_8(4)&0x7],
1595 printf( "Illegal" );
1614 printf( "if (r[0x%02x] %s ", OP_VAL_8(4)&0x0f,
1615 ifo_cmp[com.i_cmp] );
1616 IfoRegister( OP_VAL_8(5), 0 );
1627 printf( "if (r[0x%02x] %s ", OP_VAL_8(1)&0x0f,
1628 ifo_cmp[com.i_cmp] );
1629 IfoRegister( OP_VAL_16(1), com.i_dir_cmp );
1643 IfoSetSystem( com );
1645 else if( com.i_cmp && !com.i_sub_cmd )
1647 printf ("if (r[0x%02x] %s ", OP_VAL_8(4)&0x0f, ifo_cmp[com.i_cmp]);
1648 IfoRegister( OP_VAL_8(5), 0 );
1650 IfoSetSystem( com );
1652 else if( !com.i_cmp && com.i_sub_cmd )
1655 IfoSetSystem( com );
1671 else if( com.i_cmp && !com.i_sub_cmd )
1673 printf ("if (r[0x%02x] %s ", OP_VAL_8(0)&0x0f, ifo_cmp[com.i_cmp]);
1674 IfoRegister( OP_VAL_16(2), com.i_dir_cmp );
1678 else if( !com.i_cmp && com.i_sub_cmd )
1692 * math command on r[opcode[1]] and
1693 * direct?be2me_16(OP_VAL_8(0)):reg[OP_VAL_8(1)] is executed
1694 * ( unless command is swap; then r[opcode[1]] and r[OP_VAL_8(1)]
1696 * boolean operation cmp on r[opcode[1]] and
1697 * dir_cmp?be2me_16(OP_VAL_8(1)[1]):reg[OP_VAL_8(3)] is executed
1698 * on true result, buttons(c[6], c[7]) is called
1699 * problem is 'what is buttons()'
1702 printf( "r[0x%X] ", pi_code[1] );
1703 printf( " %s ", IfoMath( com.i_cmd ) );
1704 if( com.i_cmd == 2 )
1706 printf( "r[0x%X] ", OP_VAL_8(1) );
1710 IfoRegister( OP_VAL_16(0), com.i_direct );
1714 printf( "if ( r[%d] %s ", pi_code[1], ifo_cmp[com.i_cmp] );
1715 IfoRegister( OP_VAL_8(1), com.i_dir_cmp );
1716 printf( " ) then {" );
1717 IfoAdvanced( &OP_VAL_8(4) );
1722 * opposite to case 4: boolean, math and buttons.
1728 if( !com.i_direct && com.i_dir_cmp )
1730 printf( "0x%X", OP_VAL_16(1) );
1734 IfoRegister( OP_VAL_8(3), 0 );
1735 if( OP_VAL_8(3)&0x80 )
1737 printf( "s[%s]", ifo_reg[OP_VAL_8(3)&0x1F] );
1741 printf( "r[0x%X]", OP_VAL_8(3)&0x1F);
1742 // 0x1F is either not a mistake,
1743 // or Microsoft programmer's mistake!!!
1747 printf( " %s r[0x%X] ", ifo_cmp[com.i_cmp],
1748 com.i_direct ? OP_VAL_8(2) : OP_VAL_8(1) );
1749 printf( " ) then {" );
1750 printf( "r[0x%X] ", pi_code[1] & 0xF );
1751 printf( " %s ", IfoMath( com.i_cmd ) );
1753 if( com.i_cmd == 0x02 ) // swap
1755 printf("r[0x%X] ", OP_VAL_8(0)&0x1F);
1761 printf( "0x%X", OP_VAL_16(0) );
1765 if( OP_VAL_8(0) & 0x80 )
1767 printf("s[%s]", ifo_reg[OP_VAL_8(0) & 0x1F] );
1771 printf("r[0x%X]", OP_VAL_8(0) & 0x1F );
1777 IfoAdvanced( &OP_VAL_8(4) );
1783 printf( "Unknown Command\n" );
1790 /*****************************************************************************
1791 * CommandPrint : print in clear text (I hope so !) what a command does
1792 *****************************************************************************/
1793 void CommandPrint( ifo_t ifo )