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
|
203
|
99 /* WARNING: This function can only be used on a byte boundary.
|
|
100 No checks are made that we are in fact on a byte boundary.
|
|
101 */
|
|
102 static uint16_t get16bits(getbits_state_t *state) {
|
|
103 uint16_t result;
|
|
104 state->byte_position++;
|
|
105 result = (state->byte << 8) + state->start[state->byte_position++];
|
|
106 state->byte = state->start[state->byte_position];
|
|
107 return result;
|
|
108 }
|
|
109
|
|
110 /* WARNING: This function can only be used on a byte boundary.
|
|
111 No checks are made that we are in fact on a byte boundary.
|
|
112 */
|
|
113 static uint32_t get32bits(getbits_state_t *state) {
|
|
114 uint32_t result;
|
|
115 state->byte_position++;
|
|
116 result = (state->byte << 8) + state->start[state->byte_position++];
|
|
117 result = (result << 8) + state->start[state->byte_position++];
|
|
118 result = (result << 8) + state->start[state->byte_position++];
|
|
119 state->byte = state->start[state->byte_position];
|
|
120 return result;
|
|
121 }
|
|
122
|
172
|
123 void navRead_PCI(pci_t *pci, unsigned char *buffer) {
|
203
|
124 int32_t i, j;
|
172
|
125 getbits_state_t state;
|
|
126 if (getbits_init(&state, buffer)) assert(0); /* Passed NULL pointers */
|
168
|
127
|
|
128 /* pci pci_gi */
|
172
|
129 pci->pci_gi.nv_pck_lbn = getbits(&state, 32 );
|
|
130 pci->pci_gi.vobu_cat = getbits(&state, 16 );
|
|
131 pci->pci_gi.zero1 = getbits(&state, 16 );
|
|
132 pci->pci_gi.vobu_uop_ctl.zero = getbits(&state, 7 );
|
|
133 pci->pci_gi.vobu_uop_ctl.video_pres_mode_change = getbits(&state, 1 );
|
|
134
|
|
135 pci->pci_gi.vobu_uop_ctl.karaoke_audio_pres_mode_change = getbits(&state, 1 );
|
|
136 pci->pci_gi.vobu_uop_ctl.angle_change = getbits(&state, 1 );
|
|
137 pci->pci_gi.vobu_uop_ctl.subpic_stream_change = getbits(&state, 1 );
|
|
138 pci->pci_gi.vobu_uop_ctl.audio_stream_change = getbits(&state, 1 );
|
|
139 pci->pci_gi.vobu_uop_ctl.pause_on = getbits(&state, 1 );
|
|
140 pci->pci_gi.vobu_uop_ctl.still_off = getbits(&state, 1 );
|
|
141 pci->pci_gi.vobu_uop_ctl.button_select_or_activate = getbits(&state, 1 );
|
|
142 pci->pci_gi.vobu_uop_ctl.resume = getbits(&state, 1 );
|
|
143
|
|
144 pci->pci_gi.vobu_uop_ctl.chapter_menu_call = getbits(&state, 1 );
|
|
145 pci->pci_gi.vobu_uop_ctl.angle_menu_call = getbits(&state, 1 );
|
|
146 pci->pci_gi.vobu_uop_ctl.audio_menu_call = getbits(&state, 1 );
|
|
147 pci->pci_gi.vobu_uop_ctl.subpic_menu_call = getbits(&state, 1 );
|
|
148 pci->pci_gi.vobu_uop_ctl.root_menu_call = getbits(&state, 1 );
|
|
149 pci->pci_gi.vobu_uop_ctl.title_menu_call = getbits(&state, 1 );
|
|
150 pci->pci_gi.vobu_uop_ctl.backward_scan = getbits(&state, 1 );
|
|
151 pci->pci_gi.vobu_uop_ctl.forward_scan = getbits(&state, 1 );
|
|
152
|
|
153 pci->pci_gi.vobu_uop_ctl.next_pg_search = getbits(&state, 1 );
|
|
154 pci->pci_gi.vobu_uop_ctl.prev_or_top_pg_search = getbits(&state, 1 );
|
|
155 pci->pci_gi.vobu_uop_ctl.time_or_chapter_search = getbits(&state, 1 );
|
|
156 pci->pci_gi.vobu_uop_ctl.go_up = getbits(&state, 1 );
|
|
157 pci->pci_gi.vobu_uop_ctl.stop = getbits(&state, 1 );
|
|
158 pci->pci_gi.vobu_uop_ctl.title_play = getbits(&state, 1 );
|
|
159 pci->pci_gi.vobu_uop_ctl.chapter_search_or_play = getbits(&state, 1 );
|
|
160 pci->pci_gi.vobu_uop_ctl.title_or_time_play = getbits(&state, 1 );
|
|
161 pci->pci_gi.vobu_s_ptm = getbits(&state, 32 );
|
|
162 pci->pci_gi.vobu_e_ptm = getbits(&state, 32 );
|
|
163 pci->pci_gi.vobu_se_e_ptm = getbits(&state, 32 );
|
|
164 pci->pci_gi.e_eltm.hour = getbits(&state, 8 );
|
|
165 pci->pci_gi.e_eltm.minute = getbits(&state, 8 );
|
|
166 pci->pci_gi.e_eltm.second = getbits(&state, 8 );
|
|
167 pci->pci_gi.e_eltm.frame_u = getbits(&state, 8 );
|
|
168 for(i = 0; i < 32; i++)
|
|
169 pci->pci_gi.vobu_isrc[i] = getbits(&state, 8 );
|
168
|
170
|
|
171 /* pci nsml_agli */
|
|
172 for(i = 0; i < 9; i++)
|
172
|
173 pci->nsml_agli.nsml_agl_dsta[i] = getbits(&state, 32 );
|
168
|
174
|
|
175 /* pci hli hli_gi */
|
172
|
176 pci->hli.hl_gi.hli_ss = getbits(&state, 16 );
|
|
177 pci->hli.hl_gi.hli_s_ptm = getbits(&state, 32 );
|
|
178 pci->hli.hl_gi.hli_e_ptm = getbits(&state, 32 );
|
|
179 pci->hli.hl_gi.btn_se_e_ptm = getbits(&state, 32 );
|
|
180 pci->hli.hl_gi.zero1 = getbits(&state, 2 );
|
|
181 pci->hli.hl_gi.btngr_ns = getbits(&state, 2 );
|
|
182 pci->hli.hl_gi.zero2 = getbits(&state, 1 );
|
|
183 pci->hli.hl_gi.btngr1_dsp_ty = getbits(&state, 3 );
|
|
184 pci->hli.hl_gi.zero3 = getbits(&state, 1 );
|
|
185 pci->hli.hl_gi.btngr2_dsp_ty = getbits(&state, 3 );
|
|
186 pci->hli.hl_gi.zero4 = getbits(&state, 1 );
|
|
187 pci->hli.hl_gi.btngr3_dsp_ty = getbits(&state, 3 );
|
|
188 pci->hli.hl_gi.btn_ofn = getbits(&state, 8 );
|
|
189 pci->hli.hl_gi.btn_ns = getbits(&state, 8 );
|
|
190 pci->hli.hl_gi.nsl_btn_ns = getbits(&state, 8 );
|
|
191 pci->hli.hl_gi.zero5 = getbits(&state, 8 );
|
|
192 pci->hli.hl_gi.fosl_btnn = getbits(&state, 8 );
|
|
193 pci->hli.hl_gi.foac_btnn = getbits(&state, 8 );
|
168
|
194
|
|
195 /* pci hli btn_colit */
|
|
196 for(i = 0; i < 3; i++)
|
|
197 for(j = 0; j < 2; j++)
|
172
|
198 pci->hli.btn_colit.btn_coli[i][j] = getbits(&state, 32 );
|
168
|
199
|
|
200 /* NOTE: I've had to change the structure from the disk layout to get
|
|
201 * the packing to work with Sun's Forte C compiler. */
|
|
202
|
|
203 /* pci hli btni */
|
|
204 for(i = 0; i < 36; i++) {
|
172
|
205 pci->hli.btnit[i].btn_coln = getbits(&state, 2 );
|
|
206 pci->hli.btnit[i].x_start = getbits(&state, 10 );
|
|
207 pci->hli.btnit[i].zero1 = getbits(&state, 2 );
|
|
208 pci->hli.btnit[i].x_end = getbits(&state, 10 );
|
|
209
|
|
210 pci->hli.btnit[i].auto_action_mode = getbits(&state, 2 );
|
|
211 pci->hli.btnit[i].y_start = getbits(&state, 10 );
|
|
212 pci->hli.btnit[i].zero2 = getbits(&state, 2 );
|
|
213 pci->hli.btnit[i].y_end = getbits(&state, 10 );
|
|
214
|
|
215 pci->hli.btnit[i].zero3 = getbits(&state, 2 );
|
|
216 pci->hli.btnit[i].up = getbits(&state, 6 );
|
|
217 pci->hli.btnit[i].zero4 = getbits(&state, 2 );
|
|
218 pci->hli.btnit[i].down = getbits(&state, 6 );
|
|
219 pci->hli.btnit[i].zero5 = getbits(&state, 2 );
|
|
220 pci->hli.btnit[i].left = getbits(&state, 6 );
|
|
221 pci->hli.btnit[i].zero6 = getbits(&state, 2 );
|
|
222 pci->hli.btnit[i].right = getbits(&state, 6 );
|
|
223 /* pci vm_cmd */
|
|
224 for(j = 0; j < 8; j++)
|
|
225 pci->hli.btnit[i].cmd.bytes[j] = getbits(&state, 8 );
|
168
|
226 }
|
|
227
|
|
228
|
172
|
229
|
168
|
230 #ifndef NDEBUG
|
|
231 /* Asserts */
|
|
232
|
|
233 /* pci pci gi */
|
|
234 CHECK_VALUE(pci->pci_gi.zero1 == 0);
|
|
235
|
|
236 /* pci hli hli_gi */
|
|
237 CHECK_VALUE(pci->hli.hl_gi.zero1 == 0);
|
|
238 CHECK_VALUE(pci->hli.hl_gi.zero2 == 0);
|
|
239 CHECK_VALUE(pci->hli.hl_gi.zero3 == 0);
|
|
240 CHECK_VALUE(pci->hli.hl_gi.zero4 == 0);
|
|
241 CHECK_VALUE(pci->hli.hl_gi.zero5 == 0);
|
|
242
|
|
243 /* Are there buttons defined here? */
|
|
244 if((pci->hli.hl_gi.hli_ss & 0x03) != 0) {
|
|
245 CHECK_VALUE(pci->hli.hl_gi.btn_ns != 0);
|
|
246 CHECK_VALUE(pci->hli.hl_gi.btngr_ns != 0);
|
|
247 } else {
|
|
248 CHECK_VALUE((pci->hli.hl_gi.btn_ns != 0 && pci->hli.hl_gi.btngr_ns != 0)
|
|
249 || (pci->hli.hl_gi.btn_ns == 0 && pci->hli.hl_gi.btngr_ns == 0));
|
|
250 }
|
|
251
|
|
252 /* pci hli btnit */
|
|
253 for(i = 0; i < pci->hli.hl_gi.btngr_ns; i++) {
|
|
254 for(j = 0; j < (36 / pci->hli.hl_gi.btngr_ns); j++) {
|
|
255 int n = (36 / pci->hli.hl_gi.btngr_ns) * i + j;
|
|
256 CHECK_VALUE(pci->hli.btnit[n].zero1 == 0);
|
|
257 CHECK_VALUE(pci->hli.btnit[n].zero2 == 0);
|
|
258 CHECK_VALUE(pci->hli.btnit[n].zero3 == 0);
|
|
259 CHECK_VALUE(pci->hli.btnit[n].zero4 == 0);
|
|
260 CHECK_VALUE(pci->hli.btnit[n].zero5 == 0);
|
|
261 CHECK_VALUE(pci->hli.btnit[n].zero6 == 0);
|
|
262
|
|
263 if (j < pci->hli.hl_gi.btn_ns) {
|
|
264 CHECK_VALUE(pci->hli.btnit[n].x_start <= pci->hli.btnit[n].x_end);
|
|
265 CHECK_VALUE(pci->hli.btnit[n].y_start <= pci->hli.btnit[n].y_end);
|
|
266 CHECK_VALUE(pci->hli.btnit[n].up <= pci->hli.hl_gi.btn_ns);
|
|
267 CHECK_VALUE(pci->hli.btnit[n].down <= pci->hli.hl_gi.btn_ns);
|
|
268 CHECK_VALUE(pci->hli.btnit[n].left <= pci->hli.hl_gi.btn_ns);
|
|
269 CHECK_VALUE(pci->hli.btnit[n].right <= pci->hli.hl_gi.btn_ns);
|
186
|
270 /* vmcmd_verify(pci->hli.btnit[n].cmd); */
|
168
|
271 } else {
|
|
272 int k;
|
|
273 CHECK_VALUE(pci->hli.btnit[n].btn_coln == 0);
|
|
274 CHECK_VALUE(pci->hli.btnit[n].auto_action_mode == 0);
|
|
275 CHECK_VALUE(pci->hli.btnit[n].x_start == 0);
|
|
276 CHECK_VALUE(pci->hli.btnit[n].y_start == 0);
|
|
277 CHECK_VALUE(pci->hli.btnit[n].x_end == 0);
|
|
278 CHECK_VALUE(pci->hli.btnit[n].y_end == 0);
|
|
279 CHECK_VALUE(pci->hli.btnit[n].up == 0);
|
|
280 CHECK_VALUE(pci->hli.btnit[n].down == 0);
|
|
281 CHECK_VALUE(pci->hli.btnit[n].left == 0);
|
|
282 CHECK_VALUE(pci->hli.btnit[n].right == 0);
|
|
283 for (k = 0; k < 8; k++)
|
186
|
284 CHECK_VALUE(pci->hli.btnit[n].cmd.bytes[k] == 0); /* CHECK_ZERO? */
|
168
|
285 }
|
|
286 }
|
|
287 }
|
|
288 #endif /* !NDEBUG */
|
|
289 }
|
|
290
|
|
291 void navRead_DSI(dsi_t *dsi, unsigned char *buffer) {
|
|
292 int i;
|
173
|
293 getbits_state_t state;
|
|
294 if (getbits_init(&state, buffer)) assert(0); /* Passed NULL pointers */
|
168
|
295
|
|
296 /* dsi dsi gi */
|
173
|
297 dsi->dsi_gi.nv_pck_scr = getbits(&state, 32 );
|
|
298 dsi->dsi_gi.nv_pck_lbn = getbits(&state, 32 );
|
|
299 dsi->dsi_gi.vobu_ea = getbits(&state, 32 );
|
|
300 dsi->dsi_gi.vobu_1stref_ea = getbits(&state, 32 );
|
|
301 dsi->dsi_gi.vobu_2ndref_ea = getbits(&state, 32 );
|
|
302 dsi->dsi_gi.vobu_3rdref_ea = getbits(&state, 32 );
|
|
303 dsi->dsi_gi.vobu_vob_idn = getbits(&state, 16 );
|
|
304 dsi->dsi_gi.zero1 = getbits(&state, 8 );
|
|
305 dsi->dsi_gi.vobu_c_idn = getbits(&state, 8 );
|
|
306 dsi->dsi_gi.c_eltm.hour = getbits(&state, 8 );
|
|
307 dsi->dsi_gi.c_eltm.minute = getbits(&state, 8 );
|
|
308 dsi->dsi_gi.c_eltm.second = getbits(&state, 8 );
|
|
309 dsi->dsi_gi.c_eltm.frame_u = getbits(&state, 8 );
|
168
|
310
|
|
311 /* dsi sml pbi */
|
173
|
312 dsi->sml_pbi.category = getbits(&state, 16 );
|
|
313 dsi->sml_pbi.ilvu_ea = getbits(&state, 32 );
|
|
314 dsi->sml_pbi.ilvu_sa = getbits(&state, 32 );
|
|
315 dsi->sml_pbi.size = getbits(&state, 16 );
|
|
316 dsi->sml_pbi.vob_v_s_s_ptm = getbits(&state, 32 );
|
|
317 dsi->sml_pbi.vob_v_e_e_ptm = getbits(&state, 32 );
|
|
318 for(i = 0; i < 8; i++) {
|
|
319 dsi->sml_pbi.vob_a[i].stp_ptm1 = getbits(&state, 32 );
|
|
320 dsi->sml_pbi.vob_a[i].stp_ptm2 = getbits(&state, 32 );
|
|
321 dsi->sml_pbi.vob_a[i].gap_len1 = getbits(&state, 32 );
|
|
322 dsi->sml_pbi.vob_a[i].gap_len2 = getbits(&state, 32 );
|
|
323 }
|
168
|
324
|
|
325 /* dsi sml agli */
|
|
326 for(i = 0; i < 9; i++) {
|
173
|
327 dsi->sml_agli.data[ i ].address = getbits(&state, 32 );
|
|
328 dsi->sml_agli.data[ i ].size = getbits(&state, 16 );
|
168
|
329 }
|
|
330
|
|
331 /* dsi vobu sri */
|
173
|
332 dsi->vobu_sri.next_video = getbits(&state, 32 );
|
168
|
333 for(i = 0; i < 19; i++)
|
173
|
334 dsi->vobu_sri.fwda[i] = getbits(&state, 32 );
|
|
335 dsi->vobu_sri.next_vobu = getbits(&state, 32 );
|
|
336 dsi->vobu_sri.prev_vobu = getbits(&state, 32 );
|
168
|
337 for(i = 0; i < 19; i++)
|
173
|
338 dsi->vobu_sri.bwda[i] = getbits(&state, 32 );
|
|
339 dsi->vobu_sri.prev_video = getbits(&state, 32 );
|
168
|
340
|
|
341 /* dsi synci */
|
|
342 for(i = 0; i < 8; i++)
|
173
|
343 dsi->synci.a_synca[i] = getbits(&state, 16 );
|
168
|
344 for(i = 0; i < 32; i++)
|
173
|
345 dsi->synci.sp_synca[i] = getbits(&state, 32 );
|
168
|
346
|
|
347
|
|
348 /* Asserts */
|
|
349
|
|
350 /* dsi dsi gi */
|
|
351 CHECK_VALUE(dsi->dsi_gi.zero1 == 0);
|
|
352 }
|
|
353
|