00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "config.h"
00020
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <inttypes.h>
00025
00026 #include "bswap.h"
00027 #include "nav_types.h"
00028 #include "nav_read.h"
00029 #include "dvdread_internal.h"
00030
00031 typedef struct {
00032 uint8_t *start;
00033 uint32_t byte_position;
00034 uint32_t bit_position;
00035 uint8_t byte;
00036 } getbits_state_t;
00037
00038 static int getbits_init(getbits_state_t *state, uint8_t *start) {
00039 if ((state == NULL) || (start == NULL)) return 0;
00040 state->start = start;
00041 state->bit_position = 0;
00042 state->byte_position = 0;
00043 state->byte = start[0];
00044 return 1;
00045 }
00046
00047
00048
00049 static uint32_t getbits(getbits_state_t *state, uint32_t number_of_bits) {
00050 uint32_t result=0;
00051 uint8_t byte=0;
00052 if (number_of_bits > 32) {
00053 printf("Number of bits > 32 in getbits\n");
00054 abort();
00055 }
00056
00057 if ((state->bit_position) > 0) {
00058 if (number_of_bits > (8-state->bit_position)) {
00059 byte = state->byte;
00060 byte = byte >> (state->bit_position);
00061 result = byte;
00062 number_of_bits -= (8-state->bit_position);
00063 state->bit_position = 0;
00064 state->byte_position++;
00065 state->byte = state->start[state->byte_position];
00066 } else {
00067 byte=state->byte;
00068 state->byte = state->byte << number_of_bits;
00069 byte = byte >> (8 - number_of_bits);
00070 result = byte;
00071 state->bit_position += number_of_bits;
00072 if (state->bit_position == 8) {
00073 state->bit_position = 0;
00074 state->byte_position++;
00075 state->byte = state->start[state->byte_position];
00076 }
00077 number_of_bits = 0;
00078 }
00079 }
00080 if ((state->bit_position) == 0) {
00081 while (number_of_bits > 7) {
00082 result = (result << 8) + state->byte;
00083 state->byte_position++;
00084 state->byte = state->start[state->byte_position];
00085 number_of_bits -= 8;
00086 }
00087 if (number_of_bits > 0) {
00088 byte = state->byte;
00089 state->byte = state->byte << number_of_bits;
00090 state->bit_position += number_of_bits;
00091 byte = byte >> (8 - number_of_bits);
00092 result = (result << number_of_bits) + byte;
00093 number_of_bits = 0;
00094 }
00095 }
00096
00097 return result;
00098 }
00099
00100 #if 0
00101
00102
00103
00104
00105 static uint16_t get16bits(getbits_state_t *state) {
00106 uint16_t result;
00107 state->byte_position++;
00108 result = (state->byte << 8) + state->start[state->byte_position++];
00109 state->byte = state->start[state->byte_position];
00110 return result;
00111 }
00112
00113
00114
00115
00116 static uint32_t get32bits(getbits_state_t *state) {
00117 uint32_t result;
00118 state->byte_position++;
00119 result = (state->byte << 8) + state->start[state->byte_position++];
00120 result = (result << 8) + state->start[state->byte_position++];
00121 result = (result << 8) + state->start[state->byte_position++];
00122 state->byte = state->start[state->byte_position];
00123 return result;
00124 }
00125
00126 #endif
00127
00128 void navRead_PCI(pci_t *pci, unsigned char *buffer) {
00129 int32_t i, j;
00130 getbits_state_t state;
00131 if (!getbits_init(&state, buffer)) abort();
00132
00133
00134 pci->pci_gi.nv_pck_lbn = getbits(&state, 32 );
00135 pci->pci_gi.vobu_cat = getbits(&state, 16 );
00136 pci->pci_gi.zero1 = getbits(&state, 16 );
00137 pci->pci_gi.vobu_uop_ctl.zero = getbits(&state, 7 );
00138 pci->pci_gi.vobu_uop_ctl.video_pres_mode_change = getbits(&state, 1 );
00139
00140 pci->pci_gi.vobu_uop_ctl.karaoke_audio_pres_mode_change = getbits(&state, 1 );
00141 pci->pci_gi.vobu_uop_ctl.angle_change = getbits(&state, 1 );
00142 pci->pci_gi.vobu_uop_ctl.subpic_stream_change = getbits(&state, 1 );
00143 pci->pci_gi.vobu_uop_ctl.audio_stream_change = getbits(&state, 1 );
00144 pci->pci_gi.vobu_uop_ctl.pause_on = getbits(&state, 1 );
00145 pci->pci_gi.vobu_uop_ctl.still_off = getbits(&state, 1 );
00146 pci->pci_gi.vobu_uop_ctl.button_select_or_activate = getbits(&state, 1 );
00147 pci->pci_gi.vobu_uop_ctl.resume = getbits(&state, 1 );
00148
00149 pci->pci_gi.vobu_uop_ctl.chapter_menu_call = getbits(&state, 1 );
00150 pci->pci_gi.vobu_uop_ctl.angle_menu_call = getbits(&state, 1 );
00151 pci->pci_gi.vobu_uop_ctl.audio_menu_call = getbits(&state, 1 );
00152 pci->pci_gi.vobu_uop_ctl.subpic_menu_call = getbits(&state, 1 );
00153 pci->pci_gi.vobu_uop_ctl.root_menu_call = getbits(&state, 1 );
00154 pci->pci_gi.vobu_uop_ctl.title_menu_call = getbits(&state, 1 );
00155 pci->pci_gi.vobu_uop_ctl.backward_scan = getbits(&state, 1 );
00156 pci->pci_gi.vobu_uop_ctl.forward_scan = getbits(&state, 1 );
00157
00158 pci->pci_gi.vobu_uop_ctl.next_pg_search = getbits(&state, 1 );
00159 pci->pci_gi.vobu_uop_ctl.prev_or_top_pg_search = getbits(&state, 1 );
00160 pci->pci_gi.vobu_uop_ctl.time_or_chapter_search = getbits(&state, 1 );
00161 pci->pci_gi.vobu_uop_ctl.go_up = getbits(&state, 1 );
00162 pci->pci_gi.vobu_uop_ctl.stop = getbits(&state, 1 );
00163 pci->pci_gi.vobu_uop_ctl.title_play = getbits(&state, 1 );
00164 pci->pci_gi.vobu_uop_ctl.chapter_search_or_play = getbits(&state, 1 );
00165 pci->pci_gi.vobu_uop_ctl.title_or_time_play = getbits(&state, 1 );
00166 pci->pci_gi.vobu_s_ptm = getbits(&state, 32 );
00167 pci->pci_gi.vobu_e_ptm = getbits(&state, 32 );
00168 pci->pci_gi.vobu_se_e_ptm = getbits(&state, 32 );
00169 pci->pci_gi.e_eltm.hour = getbits(&state, 8 );
00170 pci->pci_gi.e_eltm.minute = getbits(&state, 8 );
00171 pci->pci_gi.e_eltm.second = getbits(&state, 8 );
00172 pci->pci_gi.e_eltm.frame_u = getbits(&state, 8 );
00173 for(i = 0; i < 32; i++)
00174 pci->pci_gi.vobu_isrc[i] = getbits(&state, 8 );
00175
00176
00177 for(i = 0; i < 9; i++)
00178 pci->nsml_agli.nsml_agl_dsta[i] = getbits(&state, 32 );
00179
00180
00181 pci->hli.hl_gi.hli_ss = getbits(&state, 16 );
00182 pci->hli.hl_gi.hli_s_ptm = getbits(&state, 32 );
00183 pci->hli.hl_gi.hli_e_ptm = getbits(&state, 32 );
00184 pci->hli.hl_gi.btn_se_e_ptm = getbits(&state, 32 );
00185 pci->hli.hl_gi.zero1 = getbits(&state, 2 );
00186 pci->hli.hl_gi.btngr_ns = getbits(&state, 2 );
00187 pci->hli.hl_gi.zero2 = getbits(&state, 1 );
00188 pci->hli.hl_gi.btngr1_dsp_ty = getbits(&state, 3 );
00189 pci->hli.hl_gi.zero3 = getbits(&state, 1 );
00190 pci->hli.hl_gi.btngr2_dsp_ty = getbits(&state, 3 );
00191 pci->hli.hl_gi.zero4 = getbits(&state, 1 );
00192 pci->hli.hl_gi.btngr3_dsp_ty = getbits(&state, 3 );
00193 pci->hli.hl_gi.btn_ofn = getbits(&state, 8 );
00194 pci->hli.hl_gi.btn_ns = getbits(&state, 8 );
00195 pci->hli.hl_gi.nsl_btn_ns = getbits(&state, 8 );
00196 pci->hli.hl_gi.zero5 = getbits(&state, 8 );
00197 pci->hli.hl_gi.fosl_btnn = getbits(&state, 8 );
00198 pci->hli.hl_gi.foac_btnn = getbits(&state, 8 );
00199
00200
00201 for(i = 0; i < 3; i++)
00202 for(j = 0; j < 2; j++)
00203 pci->hli.btn_colit.btn_coli[i][j] = getbits(&state, 32 );
00204
00205
00206
00207
00208
00209 for(i = 0; i < 36; i++) {
00210 pci->hli.btnit[i].btn_coln = getbits(&state, 2 );
00211 pci->hli.btnit[i].x_start = getbits(&state, 10 );
00212 pci->hli.btnit[i].zero1 = getbits(&state, 2 );
00213 pci->hli.btnit[i].x_end = getbits(&state, 10 );
00214
00215 pci->hli.btnit[i].auto_action_mode = getbits(&state, 2 );
00216 pci->hli.btnit[i].y_start = getbits(&state, 10 );
00217 pci->hli.btnit[i].zero2 = getbits(&state, 2 );
00218 pci->hli.btnit[i].y_end = getbits(&state, 10 );
00219
00220 pci->hli.btnit[i].zero3 = getbits(&state, 2 );
00221 pci->hli.btnit[i].up = getbits(&state, 6 );
00222 pci->hli.btnit[i].zero4 = getbits(&state, 2 );
00223 pci->hli.btnit[i].down = getbits(&state, 6 );
00224 pci->hli.btnit[i].zero5 = getbits(&state, 2 );
00225 pci->hli.btnit[i].left = getbits(&state, 6 );
00226 pci->hli.btnit[i].zero6 = getbits(&state, 2 );
00227 pci->hli.btnit[i].right = getbits(&state, 6 );
00228
00229 for(j = 0; j < 8; j++)
00230 pci->hli.btnit[i].cmd.bytes[j] = getbits(&state, 8 );
00231 }
00232
00233
00234
00235 #ifndef NDEBUG
00236
00237
00238
00239 CHECK_VALUE(pci->pci_gi.zero1 == 0);
00240
00241
00242 CHECK_VALUE(pci->hli.hl_gi.zero1 == 0);
00243 CHECK_VALUE(pci->hli.hl_gi.zero2 == 0);
00244 CHECK_VALUE(pci->hli.hl_gi.zero3 == 0);
00245 CHECK_VALUE(pci->hli.hl_gi.zero4 == 0);
00246 CHECK_VALUE(pci->hli.hl_gi.zero5 == 0);
00247
00248
00249 if((pci->hli.hl_gi.hli_ss & 0x03) != 0) {
00250 CHECK_VALUE(pci->hli.hl_gi.btn_ns != 0);
00251 CHECK_VALUE(pci->hli.hl_gi.btngr_ns != 0);
00252 } else {
00253 CHECK_VALUE((pci->hli.hl_gi.btn_ns != 0 && pci->hli.hl_gi.btngr_ns != 0)
00254 || (pci->hli.hl_gi.btn_ns == 0 && pci->hli.hl_gi.btngr_ns == 0));
00255 }
00256
00257
00258 for(i = 0; i < pci->hli.hl_gi.btngr_ns; i++) {
00259 for(j = 0; j < (36 / pci->hli.hl_gi.btngr_ns); j++) {
00260 int n = (36 / pci->hli.hl_gi.btngr_ns) * i + j;
00261 CHECK_VALUE(pci->hli.btnit[n].zero1 == 0);
00262 CHECK_VALUE(pci->hli.btnit[n].zero2 == 0);
00263 CHECK_VALUE(pci->hli.btnit[n].zero3 == 0);
00264 CHECK_VALUE(pci->hli.btnit[n].zero4 == 0);
00265 CHECK_VALUE(pci->hli.btnit[n].zero5 == 0);
00266 CHECK_VALUE(pci->hli.btnit[n].zero6 == 0);
00267
00268 if (j < pci->hli.hl_gi.btn_ns) {
00269 CHECK_VALUE(pci->hli.btnit[n].x_start <= pci->hli.btnit[n].x_end);
00270 CHECK_VALUE(pci->hli.btnit[n].y_start <= pci->hli.btnit[n].y_end);
00271 CHECK_VALUE(pci->hli.btnit[n].up <= pci->hli.hl_gi.btn_ns);
00272 CHECK_VALUE(pci->hli.btnit[n].down <= pci->hli.hl_gi.btn_ns);
00273 CHECK_VALUE(pci->hli.btnit[n].left <= pci->hli.hl_gi.btn_ns);
00274 CHECK_VALUE(pci->hli.btnit[n].right <= pci->hli.hl_gi.btn_ns);
00275
00276 } else {
00277 int k;
00278 CHECK_VALUE(pci->hli.btnit[n].btn_coln == 0);
00279 CHECK_VALUE(pci->hli.btnit[n].auto_action_mode == 0);
00280 CHECK_VALUE(pci->hli.btnit[n].x_start == 0);
00281 CHECK_VALUE(pci->hli.btnit[n].y_start == 0);
00282 CHECK_VALUE(pci->hli.btnit[n].x_end == 0);
00283 CHECK_VALUE(pci->hli.btnit[n].y_end == 0);
00284 CHECK_VALUE(pci->hli.btnit[n].up == 0);
00285 CHECK_VALUE(pci->hli.btnit[n].down == 0);
00286 CHECK_VALUE(pci->hli.btnit[n].left == 0);
00287 CHECK_VALUE(pci->hli.btnit[n].right == 0);
00288 for (k = 0; k < 8; k++)
00289 CHECK_VALUE(pci->hli.btnit[n].cmd.bytes[k] == 0);
00290 }
00291 }
00292 }
00293 #endif
00294 }
00295
00296 void navRead_DSI(dsi_t *dsi, unsigned char *buffer) {
00297 int i;
00298 getbits_state_t state;
00299 if (!getbits_init(&state, buffer)) abort();
00300
00301
00302 dsi->dsi_gi.nv_pck_scr = getbits(&state, 32 );
00303 dsi->dsi_gi.nv_pck_lbn = getbits(&state, 32 );
00304 dsi->dsi_gi.vobu_ea = getbits(&state, 32 );
00305 dsi->dsi_gi.vobu_1stref_ea = getbits(&state, 32 );
00306 dsi->dsi_gi.vobu_2ndref_ea = getbits(&state, 32 );
00307 dsi->dsi_gi.vobu_3rdref_ea = getbits(&state, 32 );
00308 dsi->dsi_gi.vobu_vob_idn = getbits(&state, 16 );
00309 dsi->dsi_gi.zero1 = getbits(&state, 8 );
00310 dsi->dsi_gi.vobu_c_idn = getbits(&state, 8 );
00311 dsi->dsi_gi.c_eltm.hour = getbits(&state, 8 );
00312 dsi->dsi_gi.c_eltm.minute = getbits(&state, 8 );
00313 dsi->dsi_gi.c_eltm.second = getbits(&state, 8 );
00314 dsi->dsi_gi.c_eltm.frame_u = getbits(&state, 8 );
00315
00316
00317 dsi->sml_pbi.category = getbits(&state, 16 );
00318 dsi->sml_pbi.ilvu_ea = getbits(&state, 32 );
00319 dsi->sml_pbi.ilvu_sa = getbits(&state, 32 );
00320 dsi->sml_pbi.size = getbits(&state, 16 );
00321 dsi->sml_pbi.vob_v_s_s_ptm = getbits(&state, 32 );
00322 dsi->sml_pbi.vob_v_e_e_ptm = getbits(&state, 32 );
00323 for(i = 0; i < 8; i++) {
00324 dsi->sml_pbi.vob_a[i].stp_ptm1 = getbits(&state, 32 );
00325 dsi->sml_pbi.vob_a[i].stp_ptm2 = getbits(&state, 32 );
00326 dsi->sml_pbi.vob_a[i].gap_len1 = getbits(&state, 32 );
00327 dsi->sml_pbi.vob_a[i].gap_len2 = getbits(&state, 32 );
00328 }
00329
00330
00331 for(i = 0; i < 9; i++) {
00332 dsi->sml_agli.data[ i ].address = getbits(&state, 32 );
00333 dsi->sml_agli.data[ i ].size = getbits(&state, 16 );
00334 }
00335
00336
00337 dsi->vobu_sri.next_video = getbits(&state, 32 );
00338 for(i = 0; i < 19; i++)
00339 dsi->vobu_sri.fwda[i] = getbits(&state, 32 );
00340 dsi->vobu_sri.next_vobu = getbits(&state, 32 );
00341 dsi->vobu_sri.prev_vobu = getbits(&state, 32 );
00342 for(i = 0; i < 19; i++)
00343 dsi->vobu_sri.bwda[i] = getbits(&state, 32 );
00344 dsi->vobu_sri.prev_video = getbits(&state, 32 );
00345
00346
00347 for(i = 0; i < 8; i++)
00348 dsi->synci.a_synca[i] = getbits(&state, 16 );
00349 for(i = 0; i < 32; i++)
00350 dsi->synci.sp_synca[i] = getbits(&state, 32 );
00351
00352
00353
00354
00355
00356 #ifdef LOG_DEBUG
00357 CHECK_VALUE(dsi->dsi_gi.zero1 == 0);
00358 #endif
00359 }
00360