… | |
… | |
19 | |
19 | |
20 | #include "config.h" |
20 | #include "config.h" |
21 | #include "compat.h" |
21 | #include "compat.h" |
22 | |
22 | |
23 | #include <stdlib.h> |
23 | #include <stdlib.h> |
|
|
24 | #include <math.h> |
24 | |
25 | |
25 | #include "parse_routines.h" |
26 | #include "parse_routines.h" |
26 | #include "error.h" |
27 | #include "error.h" |
27 | |
28 | |
28 | psiconv_u8 psiconv_read_u8(const psiconv_buffer buf,int lev,psiconv_u32 off, |
29 | psiconv_u8 psiconv_read_u8(const psiconv_buffer buf,int lev,psiconv_u32 off, |
… | |
… | |
301 | *status = localstatus; |
302 | *status = localstatus; |
302 | if (length) |
303 | if (length) |
303 | *length = 0; |
304 | *length = 0; |
304 | return NULL; |
305 | return NULL; |
305 | } |
306 | } |
|
|
307 | |
|
|
308 | psiconv_float_t psiconv_read_float(const psiconv_buffer buf, int lev, |
|
|
309 | psiconv_u32 off, int *length, int *status) |
|
|
310 | { |
|
|
311 | psiconv_float_t result,bitvalue; |
|
|
312 | int res,bit; |
|
|
313 | psiconv_u32 temp=0; |
|
|
314 | |
|
|
315 | psiconv_progress(lev+1,off,"Going to read a float"); |
|
|
316 | |
|
|
317 | bitvalue = 0.5; |
|
|
318 | result = 1.0; |
|
|
319 | for (bit = 0x33; bit > 0; bit--) { |
|
|
320 | if ((bit == 0x33) || ((bit & 0x07) == 0x07)) |
|
|
321 | temp = psiconv_read_u8(buf,lev+2,off+ (bit >> 3),&res); |
|
|
322 | if (res) |
|
|
323 | goto ERROR; |
|
|
324 | if (temp & (0x01 << (bit & 0x07))) |
|
|
325 | result += bitvalue; |
|
|
326 | bitvalue /= 2.0; |
|
|
327 | } |
|
|
328 | temp = psiconv_read_u16(buf,lev+2,off+6,&res); |
|
|
329 | if (res) |
|
|
330 | goto ERROR; |
|
|
331 | if (temp & 0x8000) |
|
|
332 | result = -result; |
|
|
333 | temp = (temp & 0x7ff0) >> 4; |
|
|
334 | result *= pow(2.0,((int) temp)-0x3ff); |
|
|
335 | psiconv_debug(lev+1,off,"Float value: %f",result); |
|
|
336 | if (length) |
|
|
337 | *length = 8; |
|
|
338 | if (*status) |
|
|
339 | *status = res; |
|
|
340 | return result; |
|
|
341 | ERROR: |
|
|
342 | psiconv_warn(lev+1,off,"Reading of float failed"); |
|
|
343 | if (length) |
|
|
344 | *length = 0; |
|
|
345 | if (*status) |
|
|
346 | *status = res; |
|
|
347 | return 0.0; |
|
|
348 | } |