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