168
|
1 /*
|
|
2 * Copyright (C) 2000, 2001, 2002, 2003 Håkan Hjort <d95hjort@dtek.chalmers.se>
|
|
3 *
|
|
4 * This program is free software; you can redistribute it and/or modify
|
|
5 * it under the terms of the GNU General Public License as published by
|
|
6 * the Free Software Foundation; either version 2 of the License, or
|
|
7 * (at your option) any later version.
|
|
8 *
|
|
9 * This program is distributed in the hope that it will be useful,
|
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 * GNU General Public License for more details.
|
|
13 *
|
|
14 * You should have received a copy of the GNU General Public License
|
|
15 * along with this program; if not, write to the Free Software
|
|
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
17 */
|
|
18
|
|
19 #include "config.h"
|
|
20
|
|
21 #include <stdio.h>
|
|
22 #include <string.h>
|
|
23 #include <inttypes.h>
|
172
|
24 #include <assert.h>
|
168
|
25
|
|
26 #include "bswap.h"
|
|
27 #include "nav_types.h"
|
|
28 #include "nav_read.h"
|
|
29 #include "dvdread_internal.h"
|
|
30
|
172
|
31 typedef struct {
|
|
32 uint8_t *start;
|
|
33 uint32_t byte_position;
|
|
34 uint32_t bit_position;
|
|
35 uint8_t byte;
|
|
36 } getbits_state_t;
|
|
37
|
|
38 static int32_t getbits_init(getbits_state_t *state, uint8_t *start) {
|
|
39 if ((state == NULL) || (start == NULL)) return -1;
|
|
40 state->start = start;
|
|
41 state->bit_position = 0;
|
|
42 state->byte_position = 0;
|
|
43 state->byte = start[0];
|
|
44 return 0;
|
|
45 }
|
|
46
|
|
47 /* Non-optimized getbits. */
|
|
48 /* This can easily be optimized for particular platforms. */
|
|
49 static uint32_t getbits(getbits_state_t *state, uint32_t number_of_bits) {
|
|
50 uint32_t result=0;
|
|
51 uint8_t byte=0;
|
|
52 if (number_of_bits > 32) {
|
|
53 printf("Number of bits > 32 in getbits\n");
|
|
54 assert(0);
|
|
55 }
|
168
|
56
|
172
|
57 if ((state->bit_position) > 0) { /* Last getbits left us in the middle of a byte. */
|
|
58 if (number_of_bits > (8-state->bit_position)) { /* this getbits will span 2 or more bytes. */
|
|
59 byte = state->byte;
|
|
60 byte = byte >> (state->bit_position);
|
|
61 result = byte;
|
|
62 number_of_bits -= (8-state->bit_position);
|
|
63 state->bit_position = 0;
|
|
64 state->byte_position++;
|
|
65 state->byte = state->start[state->byte_position];
|
|
66 } else {
|
|
67 byte=state->byte;
|
|
68 state->byte = state->byte << number_of_bits;
|
|
69 byte = byte >> (8 - number_of_bits);
|
|
70 result = byte;
|
|
71 state->bit_position += number_of_bits; /* Here it is impossible for bit_position > 8 */
|
202
|
72 if (state->bit_position == 8) {
|
|
73 state->bit_position = 0;
|
|
74 state->byte_position++;
|
|
75 state->byte = state->start[state->byte_position];
|
|
76 }
|
172
|
77 number_of_bits = 0;
|
|
78 }
|
|
79 }
|
|
80 if ((state->bit_position) == 0)
|
|
81 while (number_of_bits > 7) {
|
|
82 result = (result << 8) + state->byte;
|
|
83 state->byte_position++;
|
|
84 state->byte = state->start[state->byte_position];
|
|
85 number_of_bits -= 8;
|
|
86 }
|
|
87 if (number_of_bits > 0) { /* number_of_bits < 8 */
|
|
88 byte = state->byte;
|
|
89 state->byte = state->byte << number_of_bits;
|
|
90 state->bit_position += number_of_bits; /* Here it is impossible for bit_position > 7 */
|
|
91 byte = byte >> (8 - number_of_bits);
|
|
92 result = (result << number_of_bits) + byte;
|
|
93 number_of_bits = 0;
|
|
94 }
|
168
|
95
|
172
|
96 return result;
|
|
97 }
|
|
98
|
214
|
99 #if 0 /* TODO: optimized versions not yet used */
|
|
100
|
203
|
101 /* WARNING: This function can only be used on a byte boundary.
|
|
102 No checks are made that we are in fact on a byte boundary.
|
|
103 */
|
|
104 static uint16_t get16bits(getbits_state_t *state) {
|
|
105 uint16_t result;
|
|
106 state->byte_position++;
|
|
107 result = (state->byte << 8) + state->start[state->byte_position++];
|
|
108 state->byte = state->start[state->byte_position];
|
|
109 return result;
|
|
110 }
|
|
111
|
|
112 /* WARNING: This function can only be used on a byte boundary.
|
|
113 No checks are made that we are in fact on a byte boundary.
|
|
114 */
|
|
115 static uint32_t get32bits(getbits_state_t *state) {
|
|
116 uint32_t result;
|
|
117 state->byte_position++;
|
|
118 result = (state->byte << 8) + state->start[state->byte_position++];
|
|
119 result = (result << 8) + state->start[state->byte_position++];
|
|
120 result = (result << 8) + state->start[state->byte_position++];
|
|
121 state->byte = state->start[state->byte_position];
|
|
122 return result;
|
|
123 }
|
|
124
|
214
|
125 #endif
|
|
126
|
172
|
127 void navRead_PCI(pci_t *pci, unsigned char *buffer) {
|
203
|
128 int32_t i, j;
|
172
|
129 getbits_state_t state;
|
|
130 if (getbits_init(&state, buffer)) assert(0); /* Passed NULL pointers */
|
168
|
131
|
|
132 /* pci pci_gi */
|
172
|
133 pci->pci_gi.nv_pck_lbn = getbits(&state, 32 );
|
|
134 pci->pci_gi.vobu_cat = getbits(&state, 16 );
|
|
135 pci->pci_gi.zero1 = getbits(&state, 16 );
|
|
136 pci->pci_gi.vobu_uop_ctl.zero = getbits(&state, 7 );
|
|
137 pci->pci_gi.vobu_uop_ctl.video_pres_mode_change = getbits(&state, 1 );
|
|
138
|
|
139 pci->pci_gi.vobu_uop_ctl.karaoke_audio_pres_mode_change = getbits(&state, 1 );
|
|
140 pci->pci_gi.vobu_uop_ctl.angle_change = getbits(&state, 1 );
|
|
141 pci->pci_gi.vobu_uop_ctl.subpic_stream_change = getbits(&state, 1 );
|
|
142 pci->pci_gi.vobu_uop_ctl.audio_stream_change = getbits(&state, 1 );
|
|
143 pci->pci_gi.vobu_uop_ctl.pause_on = getbits(&state, 1 );
|
|
144 pci->pci_gi.vobu_uop_ctl.still_off = getbits(&state, 1 );
|
|
145 pci->pci_gi.vobu_uop_ctl.button_select_or_activate = getbits(&state, 1 );
|
|
146 pci->pci_gi.vobu_uop_ctl.resume = getbits(&state, 1 );
|
|
147
|
|
148 pci->pci_gi.vobu_uop_ctl.chapter_menu_call = getbits(&state, 1 );
|
|
149 pci->pci_gi.vobu_uop_ctl.angle_menu_call = getbits(&state, 1 );
|
|
150 pci->pci_gi.vobu_uop_ctl.audio_menu_call = getbits(&state, 1 );
|
|
151 pci->pci_gi.vobu_uop_ctl.subpic_menu_call = getbits(&state, 1 );
|
|
152 pci->pci_gi.vobu_uop_ctl.root_menu_call = getbits(&state, 1 );
|
|
153 pci->pci_gi.vobu_uop_ctl.title_menu_call = getbits(&state, 1 );
|
|
154 pci->pci_gi.vobu_uop_ctl.backward_scan = getbits(&state, 1 );
|
|
155 pci->pci_gi.vobu_uop_ctl.forward_scan = getbits(&state, 1 );
|
|
156
|
|
157 pci->pci_gi.vobu_uop_ctl.next_pg_search = getbits(&state, 1 );
|
|
158 pci->pci_gi.vobu_uop_ctl.prev_or_top_pg_search = getbits(&state, 1 );
|
|
159 pci->pci_gi.vobu_uop_ctl.time_or_chapter_search = getbits(&state, 1 );
|
|
160 pci->pci_gi.vobu_uop_ctl.go_up = getbits(&state, 1 );
|
|
161 pci->pci_gi.vobu_uop_ctl.stop = getbits(&state, 1 );
|
|
162 pci->pci_gi.vobu_uop_ctl.title_play = getbits(&state, 1 );
|
|
163 pci->pci_gi.vobu_uop_ctl.chapter_search_or_play = getbits(&state, 1 );
|
|
164 pci->pci_gi.vobu_uop_ctl.title_or_time_play = getbits(&state, 1 );
|
|
165 pci->pci_gi.vobu_s_ptm = getbits(&state, 32 );
|
|
166 pci->pci_gi.vobu_e_ptm = getbits(&state, 32 );
|
|
167 pci->pci_gi.vobu_se_e_ptm = getbits(&state, 32 );
|
|
168 pci->pci_gi.e_eltm.hour = getbits(&state, 8 );
|
|
169 pci->pci_gi.e_eltm.minute = getbits(&state, 8 );
|
|
170 pci->pci_gi.e_eltm.second = getbits(&state, 8 );
|
|
171 pci->pci_gi.e_eltm.frame_u = getbits(&state, 8 );
|
|
172 for(i = 0; i < 32; i++)
|
|
173 pci->pci_gi.vobu_isrc[i] = getbits(&state, 8 );
|
168
|
174
|
|
175 /* pci nsml_agli */
|
|
176 for(i = 0; i < 9; i++)
|
172
|
177 pci->nsml_agli.nsml_agl_dsta[i] = getbits(&state, 32 );
|
168
|
178
|
|
179 /* pci hli hli_gi */
|
172
|
180 pci->hli.hl_gi.hli_ss = getbits(&state, 16 );
|
|
181 pci->hli.hl_gi.hli_s_ptm = getbits(&state, 32 );
|
|
182 pci->hli.hl_gi.hli_e_ptm = getbits(&state, 32 );
|
|
183 pci->hli.hl_gi.btn_se_e_ptm = getbits(&state, 32 );
|
|
184 pci->hli.hl_gi.zero1 = getbits(&state, 2 );
|
|
185 pci->hli.hl_gi.btngr_ns = getbits(&state, 2 );
|
|
186 pci->hli.hl_gi.zero2 = getbits(&state, 1 );
|
|
187 pci->hli.hl_gi.btngr1_dsp_ty = getbits(&state, 3 );
|
|
188 pci->hli.hl_gi.zero3 = getbits(&state, 1 );
|
|
189 pci->hli.hl_gi.btngr2_dsp_ty = getbits(&state, 3 );
|
|
190 pci->hli.hl_gi.zero4 = getbits(&state, 1 );
|
|
191 pci->hli.hl_gi.btngr3_dsp_ty = getbits(&state, 3 );
|
|
192 pci->hli.hl_gi.btn_ofn = getbits(&state, 8 );
|
|
193 pci->hli.hl_gi.btn_ns = getbits(&state, 8 );
|
|
194 pci->hli.hl_gi.nsl_btn_ns = getbits(&state, 8 );
|
|
195 pci->hli.hl_gi.zero5 = getbits(&state, 8 );
|
|
196 pci->hli.hl_gi.fosl_btnn = getbits(&state, 8 );
|
|
197 pci->hli.hl_gi.foac_btnn = getbits(&state, 8 );
|
168
|
198
|
|
199 /* pci hli btn_colit */
|
|
200 for(i = 0; i < 3; i++)
|
|
201 for(j = 0; j < 2; j++)
|
172
|
202 pci->hli.btn_colit.btn_coli[i][j] = getbits(&state, 32 );
|
168
|
203
|
|
204 /* NOTE: I've had to change the structure from the disk layout to get
|
|
205 * the packing to work with Sun's Forte C compiler. */
|
|
206
|
|
207 /* pci hli btni */
|
|
208 for(i = 0; i < 36; i++) {
|
172
|
209 pci->hli.btnit[i].btn_coln = getbits(&state, 2 );
|
|
210 pci->hli.btnit[i].x_start = getbits(&state, 10 );
|
|
211 pci->hli.btnit[i].zero1 = getbits(&state, 2 );
|
|
212 pci->hli.btnit[i].x_end = getbits(&state, 10 );
|
|
213
|
|
214 pci->hli.btnit[i].auto_action_mode = getbits(&state, 2 );
|
|
215 pci->hli.btnit[i].y_start = getbits(&state, 10 );
|
|
216 pci->hli.btnit[i].zero2 = getbits(&state, 2 );
|
|
217 pci->hli.btnit[i].y_end = getbits(&state, 10 );
|
|
218
|
|
219 pci->hli.btnit[i].zero3 = getbits(&state, 2 );
|
|
220 pci->hli.btnit[i].up = getbits(&state, 6 );
|
|
221 pci->hli.btnit[i].zero4 = getbits(&state, 2 );
|
|
222 pci->hli.btnit[i].down = getbits(&state, 6 );
|
|
223 pci->hli.btnit[i].zero5 = getbits(&state, 2 );
|
|
224 pci->hli.btnit[i].left = getbits(&state, 6 );
|
|
225 pci->hli.btnit[i].zero6 = getbits(&state, 2 );
|
|
226 pci->hli.btnit[i].right = getbits(&state, 6 );
|
|
227 /* pci vm_cmd */
|
|
228 for(j = 0; j < 8; j++)
|
|
229 pci->hli.btnit[i].cmd.bytes[j] = getbits(&state, 8 );
|
168
|
230 }
|
|
231
|
|
232
|
172
|
233
|
168
|
234 #ifndef NDEBUG
|
|
235 /* Asserts */
|
|
236
|
|
237 /* pci pci gi */
|
|
238 CHECK_VALUE(pci->pci_gi.zero1 == 0);
|
|
239
|
|
240 /* pci hli hli_gi */
|
|
241 CHECK_VALUE(pci->hli.hl_gi.zero1 == 0);
|
|
242 CHECK_VALUE(pci->hli.hl_gi.zero2 == 0);
|
|
243 CHECK_VALUE(pci->hli.hl_gi.zero3 == 0);
|
|
244 CHECK_VALUE(pci->hli.hl_gi.zero4 == 0);
|
|
245 CHECK_VALUE(pci->hli.hl_gi.zero5 == 0);
|
|
246
|
|
247 /* Are there buttons defined here? */
|
|
248 if((pci->hli.hl_gi.hli_ss & 0x03) != 0) {
|
|
249 CHECK_VALUE(pci->hli.hl_gi.btn_ns != 0);
|
|
250 CHECK_VALUE(pci->hli.hl_gi.btngr_ns != 0);
|
|
251 } else {
|
|
252 CHECK_VALUE((pci->hli.hl_gi.btn_ns != 0 && pci->hli.hl_gi.btngr_ns != 0)
|
|
253 || (pci->hli.hl_gi.btn_ns == 0 && pci->hli.hl_gi.btngr_ns == 0));
|
|
254 }
|
|
255
|
|
256 /* pci hli btnit */
|
|
257 for(i = 0; i < pci->hli.hl_gi.btngr_ns; i++) {
|
|
258 for(j = 0; j < (36 / pci->hli.hl_gi.btngr_ns); j++) {
|
|
259 int n = (36 / pci->hli.hl_gi.btngr_ns) * i + j;
|
|
260 CHECK_VALUE(pci->hli.btnit[n].zero1 == 0);
|
|
261 CHECK_VALUE(pci->hli.btnit[n].zero2 == 0);
|
|
262 CHECK_VALUE(pci->hli.btnit[n].zero3 == 0);
|
|
263 CHECK_VALUE(pci->hli.btnit[n].zero4 == 0);
|
|
264 CHECK_VALUE(pci->hli.btnit[n].zero5 == 0);
|
|
265 CHECK_VALUE(pci->hli.btnit[n].zero6 == 0);
|
|
266
|
|
267 if (j < pci->hli.hl_gi.btn_ns) {
|
|
268 CHECK_VALUE(pci->hli.btnit[n].x_start <= pci->hli.btnit[n].x_end);
|
|
269 CHECK_VALUE(pci->hli.btnit[n].y_start <= pci->hli.btnit[n].y_end);
|
|
270 CHECK_VALUE(pci->hli.btnit[n].up <= pci->hli.hl_gi.btn_ns);
|
|
271 CHECK_VALUE(pci->hli.btnit[n].down <= pci->hli.hl_gi.btn_ns);
|
|
272 CHECK_VALUE(pci->hli.btnit[n].left <= pci->hli.hl_gi.btn_ns);
|
|
273 CHECK_VALUE(pci->hli.btnit[n].right <= pci->hli.hl_gi.btn_ns);
|
186
|
274 /* vmcmd_verify(pci->hli.btnit[n].cmd); */
|
168
|
275 } else {
|
|
276 int k;
|
|
277 CHECK_VALUE(pci->hli.btnit[n].btn_coln == 0);
|
|
278 CHECK_VALUE(pci->hli.btnit[n].auto_action_mode == 0);
|
|
279 CHECK_VALUE(pci->hli.btnit[n].x_start == 0);
|
|
280 CHECK_VALUE(pci->hli.btnit[n].y_start == 0);
|
|
281 CHECK_VALUE(pci->hli.btnit[n].x_end == 0);
|
|
282 CHECK_VALUE(pci->hli.btnit[n].y_end == 0);
|
|
283 CHECK_VALUE(pci->hli.btnit[n].up == 0);
|
|
284 CHECK_VALUE(pci->hli.btnit[n].down == 0);
|
|
285 CHECK_VALUE(pci->hli.btnit[n].left == 0);
|
|
286 CHECK_VALUE(pci->hli.btnit[n].right == 0);
|
|
287 for (k = 0; k < 8; k++)
|
186
|
288 CHECK_VALUE(pci->hli.btnit[n].cmd.bytes[k] == 0); /* CHECK_ZERO? */
|
168
|
289 }
|
|
290 }
|
|
291 }
|
|
292 #endif /* !NDEBUG */
|
|
293 }
|
|
294
|
|
295 void navRead_DSI(dsi_t *dsi, unsigned char *buffer) {
|
|
296 int i;
|
173
|
297 getbits_state_t state;
|
|
298 if (getbits_init(&state, buffer)) assert(0); /* Passed NULL pointers */
|
168
|
299
|
|
300 /* dsi dsi gi */
|
173
|
301 dsi->dsi_gi.nv_pck_scr = getbits(&state, 32 );
|
|
302 dsi->dsi_gi.nv_pck_lbn = getbits(&state, 32 );
|
|
303 dsi->dsi_gi.vobu_ea = getbits(&state, 32 );
|
|
304 dsi->dsi_gi.vobu_1stref_ea = getbits(&state, 32 );
|
|
305 dsi->dsi_gi.vobu_2ndref_ea = getbits(&state, 32 );
|
|
306 dsi->dsi_gi.vobu_3rdref_ea = getbits(&state, 32 );
|
|
307 dsi->dsi_gi.vobu_vob_idn = getbits(&state, 16 );
|
|
308 dsi->dsi_gi.zero1 = getbits(&state, 8 );
|
|
309 dsi->dsi_gi.vobu_c_idn = getbits(&state, 8 );
|
|
310 dsi->dsi_gi.c_eltm.hour = getbits(&state, 8 );
|
|
311 dsi->dsi_gi.c_eltm.minute = getbits(&state, 8 );
|
|
312 dsi->dsi_gi.c_eltm.second = getbits(&state, 8 );
|
|
313 dsi->dsi_gi.c_eltm.frame_u = getbits(&state, 8 );
|
168
|
314
|
|
315 /* dsi sml pbi */
|
173
|
316 dsi->sml_pbi.category = getbits(&state, 16 );
|
|
317 dsi->sml_pbi.ilvu_ea = getbits(&state, 32 );
|
|
318 dsi->sml_pbi.ilvu_sa = getbits(&state, 32 );
|
|
319 dsi->sml_pbi.size = getbits(&state, 16 );
|
|
320 dsi->sml_pbi.vob_v_s_s_ptm = getbits(&state, 32 );
|
|
321 dsi->sml_pbi.vob_v_e_e_ptm = getbits(&state, 32 );
|
|
322 for(i = 0; i < 8; i++) {
|
|
323 dsi->sml_pbi.vob_a[i].stp_ptm1 = getbits(&state, 32 );
|
|
324 dsi->sml_pbi.vob_a[i].stp_ptm2 = getbits(&state, 32 );
|
|
325 dsi->sml_pbi.vob_a[i].gap_len1 = getbits(&state, 32 );
|
|
326 dsi->sml_pbi.vob_a[i].gap_len2 = getbits(&state, 32 );
|
|
327 }
|
168
|
328
|
|
329 /* dsi sml agli */
|
|
330 for(i = 0; i < 9; i++) {
|
173
|
331 dsi->sml_agli.data[ i ].address = getbits(&state, 32 );
|
|
332 dsi->sml_agli.data[ i ].size = getbits(&state, 16 );
|
168
|
333 }
|
|
334
|
|
335 /* dsi vobu sri */
|
173
|
336 dsi->vobu_sri.next_video = getbits(&state, 32 );
|
168
|
337 for(i = 0; i < 19; i++)
|
173
|
338 dsi->vobu_sri.fwda[i] = getbits(&state, 32 );
|
|
339 dsi->vobu_sri.next_vobu = getbits(&state, 32 );
|
|
340 dsi->vobu_sri.prev_vobu = getbits(&state, 32 );
|
168
|
341 for(i = 0; i < 19; i++)
|
173
|
342 dsi->vobu_sri.bwda[i] = getbits(&state, 32 );
|
|
343 dsi->vobu_sri.prev_video = getbits(&state, 32 );
|
168
|
344
|
|
345 /* dsi synci */
|
|
346 for(i = 0; i < 8; i++)
|
173
|
347 dsi->synci.a_synca[i] = getbits(&state, 16 );
|
168
|
348 for(i = 0; i < 32; i++)
|
173
|
349 dsi->synci.sp_synca[i] = getbits(&state, 32 );
|
168
|
350
|
|
351
|
|
352 /* Asserts */
|
|
353
|
|
354 /* dsi dsi gi */
|
|
355 CHECK_VALUE(dsi->dsi_gi.zero1 == 0);
|
|
356 }
|
|
357
|