1 /* -*- c-basic-offset: 2; indent-tabs-mode: nil -*- */
3 * Copyright (C) 2000, 2001, 2002, 2003 HÃ¥kan Hjort <d95hjort@dtek.chalmers.se>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #if defined(HAVE_INTTYPES_H)
26 #elif defined(HAVE_STDINT_H)
31 #include "nav_types.h"
33 #include "dvdread_internal.h"
37 uint32_t byte_position
;
38 uint32_t bit_position
;
42 static int getbits_init(getbits_state_t
*state
, uint8_t *start
) {
43 if ((state
== NULL
) || (start
== NULL
)) return 0;
45 state
->bit_position
= 0;
46 state
->byte_position
= 0;
47 state
->byte
= start
[0];
51 /* Non-optimized getbits. */
52 /* This can easily be optimized for particular platforms. */
53 static uint32_t getbits(getbits_state_t
*state
, uint32_t number_of_bits
) {
56 if (number_of_bits
> 32) {
57 printf("Number of bits > 32 in getbits\n");
61 if ((state
->bit_position
) > 0) { /* Last getbits left us in the middle of a byte. */
62 if (number_of_bits
> (8-state
->bit_position
)) { /* this getbits will span 2 or more bytes. */
64 byte
= byte
>> (state
->bit_position
);
66 number_of_bits
-= (8-state
->bit_position
);
67 state
->bit_position
= 0;
68 state
->byte_position
++;
69 state
->byte
= state
->start
[state
->byte_position
];
72 state
->byte
= state
->byte
<< number_of_bits
;
73 byte
= byte
>> (8 - number_of_bits
);
75 state
->bit_position
+= number_of_bits
; /* Here it is impossible for bit_position > 8 */
76 if (state
->bit_position
== 8) {
77 state
->bit_position
= 0;
78 state
->byte_position
++;
79 state
->byte
= state
->start
[state
->byte_position
];
84 if ((state
->bit_position
) == 0) {
85 while (number_of_bits
> 7) {
86 result
= (result
<< 8) + state
->byte
;
87 state
->byte_position
++;
88 state
->byte
= state
->start
[state
->byte_position
];
91 if (number_of_bits
> 0) { /* number_of_bits < 8 */
93 state
->byte
= state
->byte
<< number_of_bits
;
94 state
->bit_position
+= number_of_bits
; /* Here it is impossible for bit_position > 7 */
95 byte
= byte
>> (8 - number_of_bits
);
96 result
= (result
<< number_of_bits
) + byte
;
105 void navRead_PCI(pci_t
*pci
, unsigned char *buffer
) {
107 getbits_state_t state
;
108 if (!getbits_init(&state
, buffer
)) abort(); /* Passed NULL pointers */
111 pci
->pci_gi
.nv_pck_lbn
= getbits(&state
, 32 );
112 pci
->pci_gi
.vobu_cat
= getbits(&state
, 16 );
113 pci
->pci_gi
.zero1
= getbits(&state
, 16 );
114 pci
->pci_gi
.vobu_uop_ctl
.zero
= getbits(&state
, 7 );
115 pci
->pci_gi
.vobu_uop_ctl
.video_pres_mode_change
= getbits(&state
, 1 );
117 pci
->pci_gi
.vobu_uop_ctl
.karaoke_audio_pres_mode_change
= getbits(&state
, 1 );
118 pci
->pci_gi
.vobu_uop_ctl
.angle_change
= getbits(&state
, 1 );
119 pci
->pci_gi
.vobu_uop_ctl
.subpic_stream_change
= getbits(&state
, 1 );
120 pci
->pci_gi
.vobu_uop_ctl
.audio_stream_change
= getbits(&state
, 1 );
121 pci
->pci_gi
.vobu_uop_ctl
.pause_on
= getbits(&state
, 1 );
122 pci
->pci_gi
.vobu_uop_ctl
.still_off
= getbits(&state
, 1 );
123 pci
->pci_gi
.vobu_uop_ctl
.button_select_or_activate
= getbits(&state
, 1 );
124 pci
->pci_gi
.vobu_uop_ctl
.resume
= getbits(&state
, 1 );
126 pci
->pci_gi
.vobu_uop_ctl
.chapter_menu_call
= getbits(&state
, 1 );
127 pci
->pci_gi
.vobu_uop_ctl
.angle_menu_call
= getbits(&state
, 1 );
128 pci
->pci_gi
.vobu_uop_ctl
.audio_menu_call
= getbits(&state
, 1 );
129 pci
->pci_gi
.vobu_uop_ctl
.subpic_menu_call
= getbits(&state
, 1 );
130 pci
->pci_gi
.vobu_uop_ctl
.root_menu_call
= getbits(&state
, 1 );
131 pci
->pci_gi
.vobu_uop_ctl
.title_menu_call
= getbits(&state
, 1 );
132 pci
->pci_gi
.vobu_uop_ctl
.backward_scan
= getbits(&state
, 1 );
133 pci
->pci_gi
.vobu_uop_ctl
.forward_scan
= getbits(&state
, 1 );
135 pci
->pci_gi
.vobu_uop_ctl
.next_pg_search
= getbits(&state
, 1 );
136 pci
->pci_gi
.vobu_uop_ctl
.prev_or_top_pg_search
= getbits(&state
, 1 );
137 pci
->pci_gi
.vobu_uop_ctl
.time_or_chapter_search
= getbits(&state
, 1 );
138 pci
->pci_gi
.vobu_uop_ctl
.go_up
= getbits(&state
, 1 );
139 pci
->pci_gi
.vobu_uop_ctl
.stop
= getbits(&state
, 1 );
140 pci
->pci_gi
.vobu_uop_ctl
.title_play
= getbits(&state
, 1 );
141 pci
->pci_gi
.vobu_uop_ctl
.chapter_search_or_play
= getbits(&state
, 1 );
142 pci
->pci_gi
.vobu_uop_ctl
.title_or_time_play
= getbits(&state
, 1 );
143 pci
->pci_gi
.vobu_s_ptm
= getbits(&state
, 32 );
144 pci
->pci_gi
.vobu_e_ptm
= getbits(&state
, 32 );
145 pci
->pci_gi
.vobu_se_e_ptm
= getbits(&state
, 32 );
146 pci
->pci_gi
.e_eltm
.hour
= getbits(&state
, 8 );
147 pci
->pci_gi
.e_eltm
.minute
= getbits(&state
, 8 );
148 pci
->pci_gi
.e_eltm
.second
= getbits(&state
, 8 );
149 pci
->pci_gi
.e_eltm
.frame_u
= getbits(&state
, 8 );
150 for(i
= 0; i
< 32; i
++)
151 pci
->pci_gi
.vobu_isrc
[i
] = getbits(&state
, 8 );
154 for(i
= 0; i
< 9; i
++)
155 pci
->nsml_agli
.nsml_agl_dsta
[i
] = getbits(&state
, 32 );
158 pci
->hli
.hl_gi
.hli_ss
= getbits(&state
, 16 );
159 pci
->hli
.hl_gi
.hli_s_ptm
= getbits(&state
, 32 );
160 pci
->hli
.hl_gi
.hli_e_ptm
= getbits(&state
, 32 );
161 pci
->hli
.hl_gi
.btn_se_e_ptm
= getbits(&state
, 32 );
162 pci
->hli
.hl_gi
.zero1
= getbits(&state
, 2 );
163 pci
->hli
.hl_gi
.btngr_ns
= getbits(&state
, 2 );
164 pci
->hli
.hl_gi
.zero2
= getbits(&state
, 1 );
165 pci
->hli
.hl_gi
.btngr1_dsp_ty
= getbits(&state
, 3 );
166 pci
->hli
.hl_gi
.zero3
= getbits(&state
, 1 );
167 pci
->hli
.hl_gi
.btngr2_dsp_ty
= getbits(&state
, 3 );
168 pci
->hli
.hl_gi
.zero4
= getbits(&state
, 1 );
169 pci
->hli
.hl_gi
.btngr3_dsp_ty
= getbits(&state
, 3 );
170 pci
->hli
.hl_gi
.btn_ofn
= getbits(&state
, 8 );
171 pci
->hli
.hl_gi
.btn_ns
= getbits(&state
, 8 );
172 pci
->hli
.hl_gi
.nsl_btn_ns
= getbits(&state
, 8 );
173 pci
->hli
.hl_gi
.zero5
= getbits(&state
, 8 );
174 pci
->hli
.hl_gi
.fosl_btnn
= getbits(&state
, 8 );
175 pci
->hli
.hl_gi
.foac_btnn
= getbits(&state
, 8 );
177 /* pci hli btn_colit */
178 for(i
= 0; i
< 3; i
++)
179 for(j
= 0; j
< 2; j
++)
180 pci
->hli
.btn_colit
.btn_coli
[i
][j
] = getbits(&state
, 32 );
183 for(i
= 0; i
< 36; i
++) {
184 pci
->hli
.btnit
[i
].btn_coln
= getbits(&state
, 2 );
185 pci
->hli
.btnit
[i
].x_start
= getbits(&state
, 10 );
186 pci
->hli
.btnit
[i
].zero1
= getbits(&state
, 2 );
187 pci
->hli
.btnit
[i
].x_end
= getbits(&state
, 10 );
189 pci
->hli
.btnit
[i
].auto_action_mode
= getbits(&state
, 2 );
190 pci
->hli
.btnit
[i
].y_start
= getbits(&state
, 10 );
191 pci
->hli
.btnit
[i
].zero2
= getbits(&state
, 2 );
192 pci
->hli
.btnit
[i
].y_end
= getbits(&state
, 10 );
194 pci
->hli
.btnit
[i
].zero3
= getbits(&state
, 2 );
195 pci
->hli
.btnit
[i
].up
= getbits(&state
, 6 );
196 pci
->hli
.btnit
[i
].zero4
= getbits(&state
, 2 );
197 pci
->hli
.btnit
[i
].down
= getbits(&state
, 6 );
198 pci
->hli
.btnit
[i
].zero5
= getbits(&state
, 2 );
199 pci
->hli
.btnit
[i
].left
= getbits(&state
, 6 );
200 pci
->hli
.btnit
[i
].zero6
= getbits(&state
, 2 );
201 pci
->hli
.btnit
[i
].right
= getbits(&state
, 6 );
203 for(j
= 0; j
< 8; j
++)
204 pci
->hli
.btnit
[i
].cmd
.bytes
[j
] = getbits(&state
, 8 );
212 CHECK_VALUE(pci
->pci_gi
.zero1
== 0);
215 CHECK_VALUE(pci
->hli
.hl_gi
.zero1
== 0);
216 CHECK_VALUE(pci
->hli
.hl_gi
.zero2
== 0);
217 CHECK_VALUE(pci
->hli
.hl_gi
.zero3
== 0);
218 CHECK_VALUE(pci
->hli
.hl_gi
.zero4
== 0);
219 CHECK_VALUE(pci
->hli
.hl_gi
.zero5
== 0);
221 /* Are there buttons defined here? */
222 if((pci
->hli
.hl_gi
.hli_ss
& 0x03) != 0) {
223 CHECK_VALUE(pci
->hli
.hl_gi
.btn_ns
!= 0);
224 CHECK_VALUE(pci
->hli
.hl_gi
.btngr_ns
!= 0);
226 CHECK_VALUE((pci
->hli
.hl_gi
.btn_ns
!= 0 && pci
->hli
.hl_gi
.btngr_ns
!= 0)
227 || (pci
->hli
.hl_gi
.btn_ns
== 0 && pci
->hli
.hl_gi
.btngr_ns
== 0));
231 for(i
= 0; i
< pci
->hli
.hl_gi
.btngr_ns
; i
++) {
232 for(j
= 0; j
< (36 / pci
->hli
.hl_gi
.btngr_ns
); j
++) {
233 int n
= (36 / pci
->hli
.hl_gi
.btngr_ns
) * i
+ j
;
234 CHECK_VALUE(pci
->hli
.btnit
[n
].zero1
== 0);
235 CHECK_VALUE(pci
->hli
.btnit
[n
].zero2
== 0);
236 CHECK_VALUE(pci
->hli
.btnit
[n
].zero3
== 0);
237 CHECK_VALUE(pci
->hli
.btnit
[n
].zero4
== 0);
238 CHECK_VALUE(pci
->hli
.btnit
[n
].zero5
== 0);
239 CHECK_VALUE(pci
->hli
.btnit
[n
].zero6
== 0);
241 if (j
< pci
->hli
.hl_gi
.btn_ns
) {
242 CHECK_VALUE(pci
->hli
.btnit
[n
].x_start
<= pci
->hli
.btnit
[n
].x_end
);
243 CHECK_VALUE(pci
->hli
.btnit
[n
].y_start
<= pci
->hli
.btnit
[n
].y_end
);
244 CHECK_VALUE(pci
->hli
.btnit
[n
].up
<= pci
->hli
.hl_gi
.btn_ns
);
245 CHECK_VALUE(pci
->hli
.btnit
[n
].down
<= pci
->hli
.hl_gi
.btn_ns
);
246 CHECK_VALUE(pci
->hli
.btnit
[n
].left
<= pci
->hli
.hl_gi
.btn_ns
);
247 CHECK_VALUE(pci
->hli
.btnit
[n
].right
<= pci
->hli
.hl_gi
.btn_ns
);
248 //vmcmd_verify(pci->hli.btnit[n].cmd);
251 CHECK_VALUE(pci
->hli
.btnit
[n
].btn_coln
== 0);
252 CHECK_VALUE(pci
->hli
.btnit
[n
].auto_action_mode
== 0);
253 CHECK_VALUE(pci
->hli
.btnit
[n
].x_start
== 0);
254 CHECK_VALUE(pci
->hli
.btnit
[n
].y_start
== 0);
255 CHECK_VALUE(pci
->hli
.btnit
[n
].x_end
== 0);
256 CHECK_VALUE(pci
->hli
.btnit
[n
].y_end
== 0);
257 CHECK_VALUE(pci
->hli
.btnit
[n
].up
== 0);
258 CHECK_VALUE(pci
->hli
.btnit
[n
].down
== 0);
259 CHECK_VALUE(pci
->hli
.btnit
[n
].left
== 0);
260 CHECK_VALUE(pci
->hli
.btnit
[n
].right
== 0);
261 for (k
= 0; k
< 8; k
++)
262 CHECK_VALUE(pci
->hli
.btnit
[n
].cmd
.bytes
[k
] == 0); //CHECK_ZERO?
269 void navRead_DSI(dsi_t
*dsi
, unsigned char *buffer
) {
271 getbits_state_t state
;
272 if (!getbits_init(&state
, buffer
)) abort(); /* Passed NULL pointers */
275 dsi
->dsi_gi
.nv_pck_scr
= getbits(&state
, 32 );
276 dsi
->dsi_gi
.nv_pck_lbn
= getbits(&state
, 32 );
277 dsi
->dsi_gi
.vobu_ea
= getbits(&state
, 32 );
278 dsi
->dsi_gi
.vobu_1stref_ea
= getbits(&state
, 32 );
279 dsi
->dsi_gi
.vobu_2ndref_ea
= getbits(&state
, 32 );
280 dsi
->dsi_gi
.vobu_3rdref_ea
= getbits(&state
, 32 );
281 dsi
->dsi_gi
.vobu_vob_idn
= getbits(&state
, 16 );
282 dsi
->dsi_gi
.zero1
= getbits(&state
, 8 );
283 dsi
->dsi_gi
.vobu_c_idn
= getbits(&state
, 8 );
284 dsi
->dsi_gi
.c_eltm
.hour
= getbits(&state
, 8 );
285 dsi
->dsi_gi
.c_eltm
.minute
= getbits(&state
, 8 );
286 dsi
->dsi_gi
.c_eltm
.second
= getbits(&state
, 8 );
287 dsi
->dsi_gi
.c_eltm
.frame_u
= getbits(&state
, 8 );
290 dsi
->sml_pbi
.category
= getbits(&state
, 16 );
291 dsi
->sml_pbi
.ilvu_ea
= getbits(&state
, 32 );
292 dsi
->sml_pbi
.ilvu_sa
= getbits(&state
, 32 );
293 dsi
->sml_pbi
.size
= getbits(&state
, 16 );
294 dsi
->sml_pbi
.vob_v_s_s_ptm
= getbits(&state
, 32 );
295 dsi
->sml_pbi
.vob_v_e_e_ptm
= getbits(&state
, 32 );
296 for(i
= 0; i
< 8; i
++) {
297 dsi
->sml_pbi
.vob_a
[i
].stp_ptm1
= getbits(&state
, 32 );
298 dsi
->sml_pbi
.vob_a
[i
].stp_ptm2
= getbits(&state
, 32 );
299 dsi
->sml_pbi
.vob_a
[i
].gap_len1
= getbits(&state
, 32 );
300 dsi
->sml_pbi
.vob_a
[i
].gap_len2
= getbits(&state
, 32 );
304 for(i
= 0; i
< 9; i
++) {
305 dsi
->sml_agli
.data
[ i
].address
= getbits(&state
, 32 );
306 dsi
->sml_agli
.data
[ i
].size
= getbits(&state
, 16 );
310 dsi
->vobu_sri
.next_video
= getbits(&state
, 32 );
311 for(i
= 0; i
< 19; i
++)
312 dsi
->vobu_sri
.fwda
[i
] = getbits(&state
, 32 );
313 dsi
->vobu_sri
.next_vobu
= getbits(&state
, 32 );
314 dsi
->vobu_sri
.prev_vobu
= getbits(&state
, 32 );
315 for(i
= 0; i
< 19; i
++)
316 dsi
->vobu_sri
.bwda
[i
] = getbits(&state
, 32 );
317 dsi
->vobu_sri
.prev_video
= getbits(&state
, 32 );
320 for(i
= 0; i
< 8; i
++)
321 dsi
->synci
.a_synca
[i
] = getbits(&state
, 16 );
322 for(i
= 0; i
< 32; i
++)
323 dsi
->synci
.sp_synca
[i
] = getbits(&state
, 32 );
329 CHECK_VALUE(dsi
->dsi_gi
.zero1
== 0);