Commit 1fae2100 authored by Steve Lhomme's avatar Steve Lhomme

use svn:externals on corec to the latest CoreForge location

git-svn-id: https://matroska.svn.sourceforge.net/svnroot/matroska/trunk/foundation_src@4 a6f86f6d-0131-4f8e-9e7b-e335508773d5
parent 1256241b
CONFIG_FILE config.h
PLATFORM_FILES tools/coremake
#include "*/*.proj"
This diff is collapsed.
/*****************************************************************************
*
* Copyright (c) 2008-2009, CoreCodec, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of CoreCodec, Inc. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY CoreCodec, Inc. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CoreCodec, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __ARRAY_H
#define __ARRAY_H
#include "corec.h"
#include "memheap.h"
#ifdef __cplusplus
extern "C" {
#endif
#if defined(ARRAY_EXPORTS)
#define ARRAY_DLL DLLEXPORT
#elif defined(ARRAY_IMPORTS)
#define ARRAY_DLL DLLIMPORT
#else
#define ARRAY_DLL
#endif
#define Data_Var(type,name,len) struct { size_t n; type p[len]; } __##name; type* name = (__##name.n = sizeof(__##name.p),__##name.p)
ARRAY_DLL bool_t Data_ReAlloc(uint8_t** a,size_t n);
ARRAY_DLL size_t Data_Size(const uint8_t* a);
ARRAY_DLL void Data_Release(uint8_t** a);
ARRAY_DLL void Data_Clear(uint8_t** a); // release memory, but keep heap reference
ARRAY_DLL bool_t Data_Set(uint8_t** a,const uint8_t* b,size_t pos,size_t len);
typedef struct array
{
// these are private members, use ARRAY macros to access them
uint8_t* _Begin;
uint8_t* _End;
} array;
typedef int (*arraycmp)(const void* Param, const void* a,const void* b);
#define ARRAY_AUTO_COUNT ((size_t)-1)
static INLINE void ArrayInit(array* p) { p->_Begin = NULL; p->_End = NULL; }
ARRAY_DLL void ArrayInitEx(array*,const cc_memheap*);
ARRAY_DLL void ArrayClear(array*);
ARRAY_DLL void ArrayDrop(array*);
ARRAY_DLL size_t ArraySize(const array*);
ARRAY_DLL bool_t ArrayEq(const array* a, const array* b);
ARRAY_DLL bool_t ArrayCopy(array*,const array* In);
ARRAY_DLL bool_t ArrayResize(array*,size_t Size,size_t Align);
ARRAY_DLL void ArrayZero(array*);
ARRAY_DLL intptr_t ArrayFindEx(const array* p, size_t Count, size_t Width, const void* Data, arraycmp Cmp, void* Param, bool_t* Found);
ARRAY_DLL bool_t ArrayAlloc(array* p,size_t Total,size_t Align);
ARRAY_DLL bool_t ArrayAppend(array* p, const void* Ptr, size_t Length, size_t Align);
ARRAY_DLL bool_t ArrayAppendStr(array* p, const tchar_t* Ptr, bool_t Merge, size_t Align);
ARRAY_DLL void ArrayShrink(array* p, size_t Length);
ARRAY_DLL intptr_t ArrayAddEx(array* p, size_t Count, size_t Width, const void* Data, arraycmp Cmp, void* Param, size_t Align);
ARRAY_DLL bool_t ArrayRemoveEx(array* p, size_t Count, size_t Width, const void* Data, arraycmp Cmp, void* Param);
ARRAY_DLL void ArraySortEx(array* p, size_t Count, size_t Width, arraycmp Cmp, const void* Param, bool_t Unique);
ARRAY_DLL bool_t ArrayInsert(array* p, size_t Ofs, const void* Ptr, size_t Length, size_t Align);
ARRAY_DLL void ArrayDelete(array* p, size_t Ofs, size_t Length);
ARRAY_DLL void ArrayRandomize(array* Array,size_t Width,uint32_t RndSeed);
#define ArrayAdd(p,type,Data,Cmp,Param,Align) ArrayAddEx(p,ARRAYCOUNT(*p,type),sizeof(type),Data,Cmp,Param,Align)
#define ArrayRemove(p,type,Data,Cmp,Param) ArrayRemoveEx(p,ARRAYCOUNT(*p,type),sizeof(type),Data,Cmp,Param)
#define ArrayFind(p,type,Data,Cmp,Param,Found) ArrayFindEx(p,ARRAYCOUNT(*p,type),sizeof(type),Data,Cmp,Param,Found)
#define ArraySort(p,type,Cmp,Param,Unique) ArraySortEx(p,ARRAYCOUNT(*p,type),sizeof(type),Cmp,Param,Unique)
#ifdef CONFIG_DEBUGCHECKS
#define ARRAYBEGIN(Array,Type) (assert(&(Array)!=NULL),(Type*)((Array)._Begin))
#define ARRAYEND(Array,Type) (assert(&(Array)!=NULL),(Type*)((Array)._End))
#define ARRAYEMPTY(Array) (assert(&(Array)!=NULL),(Array)._Begin==(Array)._End)
#else
#define ARRAYBEGIN(Array,Type) ((Type*)((Array)._Begin))
#define ARRAYEND(Array,Type) ((Type*)((Array)._End))
#define ARRAYEMPTY(Array) ((Array)._Begin==(Array)._End)
#endif
#define ARRAYCOUNT(Array,Type) ((size_t)(ARRAYEND(Array,Type)-ARRAYBEGIN(Array,Type)))
// TODO: move this to base/mem and depend on "mem" platform dependently(?)
typedef struct block
{
const uint8_t* Ptr;
uintptr_t Id;
} block;
//end TODO
#ifdef TARGET_PALMOS
typedef struct arrayblock
{
array Array;
block Block;
} arrayblock;
ARRAY_DLL void ArrayBlockClear(arrayblock*);
ARRAY_DLL void ArrayBlockLock(arrayblock*);
#else
typedef struct arrayblock
{
array Array;
} arrayblock;
#define ArrayBlockClear(a) ArrayClear(&(a)->Array)
#define ArrayBlockLock(a) {}
#endif
#define SAFETAIL 256
typedef struct cc_fifo
{
// private members
array _Base;
uint8_t* _Read;
} cc_fifo;
static INLINE void Fifo_Init(cc_fifo* p) { ArrayInit(&p->_Base); p->_Read = NULL; }
ARRAY_DLL void Fifo_Clear(cc_fifo*);
ARRAY_DLL void Fifo_Drop(cc_fifo*);
ARRAY_DLL bool_t Fifo_Alloc(cc_fifo* p, size_t Size, size_t Align);
ARRAY_DLL uint8_t* Fifo_Write(cc_fifo*, const void* Ptr, size_t Length, size_t Align);
static INLINE void Fifo_Readed(cc_fifo* p, size_t Length)
{
p->_Read += Length;
}
#define FIFO_SIZE(p) (ARRAYEND((p)._Base,uint8_t)-(p)._Read)
#define FIFO_BEGIN(p) ((p)._Read)
#define FIFO_END(p) ARRAYEND((p)._Base,uint8_t)
#ifdef __cplusplus
}
#endif
#endif
GROUP array
{
USE corec
SOURCE array.c
HEADER array.h
}
/*****************************************************************************
*
* Copyright (c) 2008-2009, CoreCodec, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of CoreCodec, Inc. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY CoreCodec, Inc. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CoreCodec, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __COREC_H
#define __COREC_H
#ifdef __cplusplus
extern "C" {
#endif
#if defined(_MSC_VER) && (_MSC_VER > 1000)
#pragma once
#pragma warning(push, 4)
#pragma warning(disable : 4100 4710 4514 4201 4714 4115 4206 4055 4214 4998 4273 4127)
#endif
#include "portab.h"
#include "memalloc.h"
#include "err.h"
#include "helper.h"
#if defined(NDEBUG) && defined(CONFIG_DEBUGCHECKS)
#undef CONFIG_DEBUGCHECKS
#endif
#ifdef __cplusplus
}
#endif
#endif /* __COREC_H */
#include "*/*.proj"
GROUP corec
{
INCLUDE .
EXPINCLUDE .
HEADER corec.h
HEADER err.h
HEADER fixed.h
HEADER helper.h
HEADER memalloc.h
HEADER portab.h
}
/*****************************************************************************
*
* Copyright (c) 2008-2009, CoreCodec, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of CoreCodec, Inc. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY CoreCodec, Inc. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CoreCodec, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __ERR_H
#define __ERR_H
#define ERR_ID FOURCC('E','R','R','_')
//----------------------------------------------------------------
// error codes
#define ERR_NONE (err_t)0
#define ERR_BUFFER_FULL (err_t)-1
#define ERR_OUT_OF_MEMORY (err_t)-2
#define ERR_INVALID_DATA (err_t)-3
#define ERR_INVALID_PARAM (err_t)-4
#define ERR_NOT_SUPPORTED (err_t)-5
#define ERR_NEED_MORE_DATA (err_t)-6
#define ERR_FILE_NOT_FOUND (err_t)-8
#define ERR_END_OF_FILE (err_t)-9
#define ERR_DEVICE_ERROR (err_t)-10
#define ERR_SYNCED (err_t)-11
#define ERR_DATA_NOT_FOUND (err_t)-12
#define ERR_PROTO_NOT_FOUND (err_t)-13
#define ERR_NOT_DIRECTORY (err_t)-14
#define ERR_NOT_COMPATIBLE (err_t)-15
#define ERR_CONNECT_FAILED (err_t)-16
#define ERR_DROPPING (err_t)-17
#define ERR_STOPPED (err_t)-18
#define ERR_UNAUTHORIZED (err_t)-19
#define ERR_LOADING_HEADER (err_t)-20
#define ERR_READ (err_t)-21
#define ERR_WRITE (err_t)-22
#define ERR_UNRESOLVED_ADDR (err_t)-23
#define ERR_NO_NETWORK (err_t)-24
#define ERR_TIME_OUT (err_t)-25
#define ERR_KEY_NOT_UNIQUE (err_t)-26
#define ERR_NOT_CONST (err_t)-27
#define ERR_REDIRECTED (err_t)-28
#define ERR_CANCELED (err_t)-29
#define ERR_STREAM_CACHED (err_t)-30
#define ERR_SERVER_ERROR (err_t)-31
// buffer full: data is not processed, retry later
// need more data: data is processed, but need more to continue
#endif
/*****************************************************************************
*
* Copyright (c) 2008-2009, CoreCodec, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of CoreCodec, Inc. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY CoreCodec, Inc. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CoreCodec, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __HELPER_H
#define __HELPER_H
#ifdef TARGET_LINUX
#include <stddef.h>
#define OFS(name,item) offsetof(name,item)
#else
#define OFS(name,item) ((uintptr_t)&(((name*)NULL)->item))
#endif
#define ALIGN64(x) (((x) + 63) & ~63)
#define ALIGN16(x) (((x) + 15) & ~15)
#define ALIGN8(x) (((x) + 7) & ~7)
#define ALIGN4(x) (((x) + 3) & ~3)
#define ALIGN2(x) (((x) + 1) & ~1)
#define GET_R(x) ((uint8_t)(((x) >> 0) & 255))
#define GET_G(x) ((uint8_t)(((x) >> 8) & 255))
#define GET_B(x) ((uint8_t)(((x) >> 16) & 255))
#define SWAP32(a) ((((uint32_t)(a) >> 24) & 0x000000FF) | (((uint32_t)(a) >> 8) & 0x0000FF00)|\
(((uint32_t)(a) << 8) & 0x00FF0000) | (((uint32_t)(a) << 24) & 0xFF000000))
#define SWAP16(a) ((uint16_t)((((uint32_t)(a) >> 8) & 0xFF) | (((uint32_t)(a) << 8) & 0xFF00)))
#define SWAP64(a) (((uint64_t)SWAP32(a) << 32) | SWAP32((uint64_t)(a)>>32))
#define LSHIFT(v,n) ((v)<<(n))
#define RSHIFT(v,n) ((v)>>(n))
#define RLSHIFT(v,n) (((n)>=0)?RSHIFT(v,n):LSHIFT(v,-(n)))
#define RSHIFT_ROUND(v,n) (((v)+(1<<(n-1)))>>(n))
#define RSHIFT_ROUND_COND(v,n) ((n)>0 ? RSHIFT_ROUND(v,n) : v)
#ifdef IS_BIG_ENDIAN
#define INT64BE(a) (a)
#define INT64LE(a) SWAP64(a)
#define INT32BE(a) (a)
#define INT32LE(a) SWAP32(a)
#define INT16BE(a) (a)
#define INT16LE(a) SWAP16(a)
#else
#define INT64LE(a) (a)
#define INT64BE(a) SWAP64(a)
#define INT32LE(a) (a)
#define INT32BE(a) SWAP32(a)
#define INT16LE(a) (a)
#define INT16BE(a) SWAP16(a)
#endif
#if defined(CONFIG_UNALIGNED_ACCESS)
#define LOAD16LE(ptr) INT16LE(*(uint16_t*)(ptr))
#define LOAD16BE(ptr) INT16BE(*(uint16_t*)(ptr))
#define LOAD32LE(ptr) INT32LE(*(uint32_t*)(ptr))
#define LOAD32BE(ptr) INT32BE(*(uint32_t*)(ptr))
#define LOAD64LE(ptr) INT64LE(*(uint64_t*)(ptr))
#define LOAD64BE(ptr) INT64BE(*(uint64_t*)(ptr))
#else
#define LOAD8(ptr,ofs) (((uint8_t*)(ptr))[ofs])
#define LOAD16LE(ptr) ((uint16_t)((LOAD8(ptr,1)<<8)|LOAD8(ptr,0)))
#define LOAD16BE(ptr) ((uint16_t)((LOAD8(ptr,0)<<8)|LOAD8(ptr,1)))
#define LOAD32LE(ptr) ((LOAD8(ptr,3)<<24)|(LOAD8(ptr,2)<<16)|(LOAD8(ptr,1)<<8)|LOAD8(ptr,0))
#define LOAD32BE(ptr) ((LOAD8(ptr,0)<<24)|(LOAD8(ptr,1)<<16)|(LOAD8(ptr,2)<<8)|LOAD8(ptr,3))
#define LOAD64LE(ptr) ((((uint64_t)LOAD8(ptr,0)) )|(((uint64_t)LOAD8(ptr,1))<< 8)|(((uint64_t)LOAD8(ptr,2))<<16)|(((uint64_t)LOAD8(ptr,3))<<24)| \
(((uint64_t)LOAD8(ptr,4))<<32)|(((uint64_t)LOAD8(ptr,5))<<40)|(((uint64_t)LOAD8(ptr,6))<<48)|(((uint64_t)LOAD8(ptr,0))<<56))
#define LOAD64BE(ptr) ((((uint64_t)LOAD8(ptr,0))<<56)|(((uint64_t)LOAD8(ptr,1))<<48)|(((uint64_t)LOAD8(ptr,2))<<40)|(((uint64_t)LOAD8(ptr,3))<<32)| \
(((uint64_t)LOAD8(ptr,4))<<24)|(((uint64_t)LOAD8(ptr,5))<<16)|(((uint64_t)LOAD8(ptr,6))<< 8)|(((uint64_t)LOAD8(ptr,0)) ))
#endif
#define STORE8(p, o, i) ((uint8_t *) (p))[o] = (uint8_t) ((i) & 0xFF)
#if defined(CONFIG_UNALIGNED_ACCESS) && defined(IS_BIG_ENDIAN)
#define STORE16BE(p, i) *((uint16_t*)(p))=i
#define STORE32BE(p, i) *((uint32_t*)(p))=i
#define STORE64BE(p, i) *((uint64_t*)(p))=i
#else
#define STORE16BE(p, i) STORE8(p, 1, i), STORE8(p, 0, ((uint16_t)i) >> 8)
#define STORE32BE(p, i) STORE8(p, 3, i), STORE8(p, 2, ((uint32_t)i) >> 8), STORE8(p, 1, ((uint32_t) i) >> 16), STORE8(p, 0, ((uint32_t) i) >> 24)
#define STORE64BE(p, i) STORE8(p, 7, i), STORE8(p, 6, ((uint64_t)i) >> 8), STORE8(p, 5, ((uint64_t)i) >> 16), STORE8(p, 4, ((uint64_t)i) >> 24), \
STORE8(p, 3, ((uint64_t)i) >> 32), STORE8(p, 2, ((uint64_t)i) >> 40), STORE8(p, 1, ((uint64_t)i) >> 48), STORE8(p, 0, ((uint64_t)i) >> 56)
#endif
#if defined(CONFIG_UNALIGNED_ACCESS) && defined(IS_LITTLE_ENDIAN)
#define STORE16LE(p, i) *((uint16_t*)(p))=i
#define STORE32LE(p, i) *((uint32_t*)(p))=i
#define STORE64LE(p, i) *((uint64_t*)(p))=i
#else
#define STORE16LE(p, i) STORE8(p, 0, i), STORE8(p, 1, ((uint16_t)i) >> 8)
#define STORE32LE(p, i) STORE8(p, 0, i), STORE8(p, 1, ((uint32_t)i) >> 8), STORE8(p, 2, ((uint32_t)i) >> 16), STORE8(p, 3, ((uint32_t)i) >> 24)
#define STORE64LE(p, i) STORE8(p, 0, i), STORE8(p, 1, ((uint64_t)i) >> 8), STORE8(p, 2, ((uint64_t)i) >> 16), STORE8(p, 3, ((uint64_t)i) >> 24), \
STORE8(p, 4, ((uint64_t)i) >> 32), STORE8(p, 5, ((uint64_t)i) >> 40), STORE8(p, 6, ((uint64_t)i) >> 48), STORE8(p, 7, ((uint64_t)i) >> 56)
#endif
#ifdef IS_BIG_ENDIAN
#define LOAD16(ptr) LOAD16BE(ptr)
#define LOAD32(ptr) LOAD32BE(ptr)
#define LOAD64(ptr) LOAD64BE(ptr)
#define LOAD16SW(ptr) LOAD16LE(ptr)
#define LOAD32SW(ptr) LOAD32LE(ptr)
#define LOAD64SW(ptr) LOAD64LE(ptr)
#else
#define LOAD16(ptr) LOAD16LE(ptr)
#define LOAD32(ptr) LOAD32LE(ptr)
#define LOAD64(ptr) LOAD64LE(ptr)
#define LOAD16SW(ptr) LOAD16BE(ptr)
#define LOAD32SW(ptr) LOAD32BE(ptr)
#define LOAD64SW(ptr) LOAD64BE(ptr)
#endif
#if defined(__GNUC__) && defined(MIPS)
#undef LOAD32
static INLINE uint32_t LOAD32(const void* ptr) { uint32_t v; asm ("ulw %0,0(%1)\n" : "=&r" (v) : "r" (ptr)); return v; }
#endif
// a=(a+c+1)/2
// b=(b+d+1)/2
#define AVG32R(a,b,c,d) \
c^=a; \
d^=b; \
a|=c; \
b|=d; \
c &= 0xFEFEFEFE; \
d &= 0xFEFEFEFE; \
a-=c>>1; \
b-=d>>1;
#define AVG64R(a,b,c,d) \
c^=a; \
d^=b; \
a|=c; \
b|=d; \
c &= 0xFEFEFEFEFEFEFEFE; \
d &= 0xFEFEFEFEFEFEFEFE; \
a-=c>>1; \
b-=d>>1;
// a=(a+c)/2
// b=(b+d)/2
#ifdef ARM
#define AVG32NR(a,b,c,d) \
c^=a; \
d^=b; \
a &= ~c; \
b &= ~d; \
c &= 0xFEFEFEFE; \
d &= 0xFEFEFEFE; \
a+=c>>1; \
b+=d>>1;
#else
#define AVG32NR(a,b,c,d) \
c^=a; \
d^=b; \
a|=c; \
b|=d; \
a-=c & 0x01010101; \
b-=d & 0x01010101; \
c &= 0xFEFEFEFE; \
d &= 0xFEFEFEFE; \
a-=c>>1; \
b-=d>>1;
#endif
#define AVG64NR(a,b,c,d) \
c^=a; \
d^=b; \
a|=c; \
b|=d; \
a-=c & 0x0101010101010101; \
b-=d & 0x0101010101010101; \
c &= 0xFEFEFEFEFEFEFEFE; \
d &= 0xFEFEFEFEFEFEFEFE; \
a-=c>>1; \
b-=d>>1;
#define _abs(a) (((a)>=0)?(a):-(a))
static INLINE int MIDDLE(int a, int b, int c)
{
int bb = b;
if (a > b)
{
bb = a;
a = b;
}
if (bb > c)
bb = c;
if (a > bb)
bb = a;
return bb;
}
static INLINE size_t _log2(uint32_t data)
{
size_t i;
if (!data) ++data;
for (i=0;data;++i)
data >>= 1;
return i;
}
static INLINE int64_t Scale64(int64_t v,int64_t Num,int64_t Den)
{
if (Den)
return (v * Num) / Den;
return 0;
}
static INLINE int Scale32(int64_t v, int64_t Num, int64_t Den)
{
return (int)Scale64(v,Num,Den);
}
#define SWAPVAL(type,a,b) { type __t = (a); (a)=(b); (b)=__t; }
typedef int32_t datetime_t;
#define INVALID_DATETIME_T 0
#define MIN_DATETIME_T ((datetime_t) 0xFFFFFFFF)
#define MAX_DATETIME_T ((datetime_t) 0x7FFFFFFF)
static INLINE int Fix16Mul(int a,int b)
{
return (int)(((int64_t)(a<<8)*(int64_t)(b<<8))>>32);
}
static INLINE uint32_t _ones(uint32_t x)
{
x -= ((x >> 1) & 0x55555555);
x = (((x >> 2) & 0x33333333) + (x & 0x33333333));
x = (((x >> 4) + x) & 0x0f0f0f0f);
x += (x >> 8);
x += (x >> 16);
return x & 0x0000003f;
}
static INLINE uint32_t _floor_log2(uint32_t x)
{
x |= (x >> 1);
x |= (x >> 2);
x |= (x >> 4);
x |= (x >> 8);
x |= (x >> 16);
return _ones(x) - 1;
}
#endif
#include <stdlib.h>
#include <string.h>
GROUP libc
{
IF TARGET_PALMOS
USE palmone_sdk
USE sony_sdk
USEINCLUDE base
USEINCLUDE peal
SYSINCLUDE palmos
SOURCE palmos/assert.c
SOURCE(ARM) palmos/math.c
SOURCE(ARM) palmos/qsort.c
SOURCE(ARM) palmos/rand.c
SOURCE(ARM) palmos/sincos.c
SOURCE(ARM) palmos/vsprintf.c
SOURCE(ARM) palmos/setjmp.S
SOURCE palmos/pace.c
SOURCE palmos/pace2.c
SOURCE(IX86) palmos/native_x86.c
SOURCE(ARM) palmos/native_arm.S
ENDIF
IF TARGET_SYMBIAN
SYSINCLUDE symbian
ENDIF
IF TARGET_WINCE
USEINCLUDE base
SOURCE wince/assert.c
SYSINCLUDE wince
ENDIF
IF TARGET_PS2SDK
USE ps2event
SYSINCLUDE ps2sdk
ENDIF
IF TARGET_IPHONE_SDK
SYSINCLUDE iphone
ENDIF
}
GROUP con_to_exe
{
SOURCE(TARGET_WINCE) wince/console_wince.c
IF TARGET_PALMOS
USEINCLUDE peal
USE peal
USE libc
SOURCE palmos/console_palmos.c
SOURCE_M68K palmos/console_palmos_m68k.c
ENDIF
}
/*****************************************************************************
*
* Copyright (c) 2008-2009, CoreCodec, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of CoreCodec, Inc. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY CoreCodec, Inc. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL CoreCodec, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#define ASSERT_INTERNAL
#include "base.h"
#ifndef NDEBUG
#ifdef LIBC_EXPORTS
#define ASSERT_DLL DLLEXPORT
#else
#define ASSERT_DLL
#endif
#define WarningOKAlert 10031
extern uint16_t FrmCustomAlert(uint16_t alertId, const char *s1, const char *s2, const char *s3);
ASSERT_DLL void _Assert(const char* Exp, const char* File, int Line)
{
char Msg[MAXPATH];
size_t i;
int n=1000000;
Msg[0] = '\n';
for (i=1;i<MAXPATH-1 && File[i];++i)
Msg[i] = File[i];
if (i<MAXPATH-1)
Msg[i