… | |
… | |
24 | #include <math.h> |
24 | #include <math.h> |
25 | |
25 | |
26 | #include "parse_routines.h" |
26 | #include "parse_routines.h" |
27 | #include "error.h" |
27 | #include "error.h" |
28 | |
28 | |
|
|
29 | /* Very inefficient, but good enough for now. By implementing it ourselves, |
|
|
30 | we do not have to link with -lm */ |
|
|
31 | psiconv_float_t pow2(int n) |
|
|
32 | { |
|
|
33 | psiconv_float_t res=1.0; |
|
|
34 | int i; |
|
|
35 | |
|
|
36 | for (i = 0; i < (n<0?-n:n); i++) |
|
|
37 | res *= 2.0; |
|
|
38 | |
|
|
39 | return n<0?1/res:res; |
|
|
40 | } |
29 | psiconv_u8 psiconv_read_u8(const psiconv_buffer buf,int lev,psiconv_u32 off, |
41 | psiconv_u8 psiconv_read_u8(const psiconv_buffer buf,int lev,psiconv_u32 off, |
30 | int *status) |
42 | int *status) |
31 | { |
43 | { |
32 | psiconv_u8 *ptr; |
44 | psiconv_u8 *ptr; |
33 | ptr = psiconv_buffer_get(buf,off); |
45 | ptr = psiconv_buffer_get(buf,off); |
… | |
… | |
76 | if (status) |
88 | if (status) |
77 | *status = 0; |
89 | *status = 0; |
78 | return *ptr0 + (*ptr1 << 8) + (*ptr2 << 16) + (*ptr3 << 24); |
90 | return *ptr0 + (*ptr1 << 8) + (*ptr2 << 16) + (*ptr3 << 24); |
79 | } |
91 | } |
80 | |
92 | |
|
|
93 | psiconv_s32 psiconv_read_sint(const psiconv_buffer buf,int lev,psiconv_u32 off, |
|
|
94 | int *length,int *status) |
|
|
95 | { |
|
|
96 | int localstatus; |
|
|
97 | psiconv_u32 temp; |
|
|
98 | |
|
|
99 | temp=psiconv_read_u32(buf,lev,off,&localstatus); |
|
|
100 | if (status) |
|
|
101 | *status = localstatus; |
|
|
102 | if (length) |
|
|
103 | *length = localstatus?0:4; |
|
|
104 | |
|
|
105 | return localstatus?0:(temp & 0x7fffffff)*(temp&0x80000000?-1:1); |
|
|
106 | } |
|
|
107 | |
81 | psiconv_S_t psiconv_read_S(const psiconv_buffer buf, int lev, psiconv_u32 off, |
108 | psiconv_S_t psiconv_read_S(const psiconv_buffer buf, int lev, psiconv_u32 off, |
82 | int *length,int *status) |
109 | int *length,int *status) |
83 | { |
110 | { |
84 | psiconv_u8 temp; |
111 | psiconv_u8 temp; |
85 | psiconv_S_t res; |
112 | psiconv_S_t res; |
… | |
… | |
384 | if (res) |
411 | if (res) |
385 | goto ERROR; |
412 | goto ERROR; |
386 | if (temp & 0x8000) |
413 | if (temp & 0x8000) |
387 | result = -result; |
414 | result = -result; |
388 | temp = (temp & 0x7ff0) >> 4; |
415 | temp = (temp & 0x7ff0) >> 4; |
389 | result *= pow(2.0,((int) temp)-0x3ff); |
416 | result *= pow2(((int) temp)-0x3ff); |
390 | psiconv_debug(lev+1,off,"Float value: %f",result); |
417 | psiconv_debug(lev+1,off,"Float value: %f",result); |
391 | if (length) |
418 | if (length) |
392 | *length = 8; |
419 | *length = 8; |
393 | if (*status) |
420 | if (*status) |
394 | *status = res; |
421 | *status = res; |
… | |
… | |
399 | *length = 0; |
426 | *length = 0; |
400 | if (*status) |
427 | if (*status) |
401 | *status = res; |
428 | *status = res; |
402 | return 0.0; |
429 | return 0.0; |
403 | } |
430 | } |
|
|
431 | |