// Header File
// Created 08/01/2010; 21:18:14

extern void FastDrawLine(void* plane,short x1,short y1,short x2,short y2,short mode) __attribute__((__stkparm__));		//Est plus rapide que la version Register
//void FastLine_Draw_R(void *plane asm("%a0"),short x1 asm("%d0"),short y1 asm("%d1"),short x2 asm("%d2"),short y2 asm("%d3"));
//void FastDrawLine_R (void* plane asm("%a0"),unsigned short x1 asm("%d0"),unsigned short y1 asm("%d1"),unsigned short x2 asm("%d2"),unsigned short y2 asm("%d3"),unsigned short mode) __attribute__ ((__stkparm__));
void FastDrawHLine(unsigned char* plane,short x1,short x2,short y,short mode) __attribute__((__stkparm__));
void FastDrawVLine(unsigned char* plane,short x,short y1,short y2,short mode) __attribute__((__stkparm__));

//void Sprite8_OR(short x,short y,short h,unsigned char* sprite,void* dest);
//void Sprite8_XOR(short x,short y,short h,unsigned char* sprite,void* dest);
//void Sprite8_AND(short x,short y,short h,unsigned char* sprite,void* dest);
//void Sprite8_RPLC_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned char *sprt asm("%a1"),void *dest asm("%a0"));

//void Sprite16_OR(short x,short y,short h,unsigned char* sprite,void* dest);
//void Sprite16_XOR(short x,short y,short h,unsigned char* sprite,void* dest);
//void Sprite16_AND(short x,short y,short h,unsigned char* sprite,void* dest);
//void Sprite16_RPLC_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned char *sprt asm("%a1"),void *dest asm("%a0"));

//void Sprite32_OR(short x,short y,short h,unsigned char* sprite,void* dest);
//void Sprite32_XOR(short x,short y,short h,unsigned char* sprite,void* dest);
//void Sprite32_AND(short x,short y,short h,unsigned char* sprite,void* dest);
//void Sprite32_RPLC_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned char *sprt asm("%a1"),void *dest asm("%a0"));

void FastCopyScreen(void* src,void* dest) __attribute__((__stkparm__));  // C prototype
void FastCopyScreen_R(void* src asm("%a0"),void* dest asm("%a1")) __attribute__((__regparm__(2)));  // C prototype

void ClipSprite8_OR_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned char *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite8_XOR_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned char *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite8_AND_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned char *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite8_RPLC_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned char *sprt asm("%a1"),void *dest asm("%a0")) __attribute__((__regparm__));

void ClipSprite16_OR_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned short *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite16_XOR_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned short *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite16_AND_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned short *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite16_RPLC_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned short *sprt asm("%a1"),void *dest asm("%a0")) __attribute__((__regparm__));

void ClipSprite32_OR_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned long *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite32_XOR_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned long *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite32_AND_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned long *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite32_RPLC_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned long *sprt asm("%a1"),void *dest asm("%a0")) __attribute__((__regparm__));

void ClipSprite8Get_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned char *sprt asm("%a1"),void *dest asm("%a0"));
void ClipSprite16Get_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned short *sprt asm("%a1"),void *dest asm("%a0")) __attribute__((__regparm__));
void ClipSprite32Get_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),unsigned long *sprt asm("%a1"),void *dest asm("%a0"));

short TestCollide8(short x0 asm("%d0"), short y0 asm("%d1"), short x1 asm("%d2"), short y1 asm("%d3"), short height, const unsigned char* data0 asm("%a0"), const unsigned char* data1 asm("%a1")) __attribute__((__stkparm__));
short TestCollide16(short x0, short y0, short x1, short y1, short height, const unsigned short* data0, const unsigned short* data1) __attribute__((__stkparm__));

void FastFilledRect(void* plane,short x1,short y1,short x2,short y2,short mode) __attribute__((__stkparm__));

//FOR Fast pixel get state :
#define EXT_PIXOFFSET(x, y) ((((y)<<4)-(y))*2+((x)>>3))
#define EXT_GETPIX_AN(a, offset, n) ({char __result; if(__builtin_constant_p(offset)) \
	{ \
		if(__builtin_constant_p(a)) \
			asm("btst.b %1,%c2; sne.b %0" : "=d" (__result) : "di" (n), "dai" ((offset)+(unsigned char*)(a))); \
		else \
			if (offset !=0) \
				asm("btst.b %1,%c2(%3); sne.b %0" : "=d,d" (__result) : "di,di" (n), "i,\?\?\?\?!g" (offset), "a,a" (a)); \
			else \
				asm("btst.b %1,(%2); sne.b %0" : "=d" (__result) : "di" (n), "a" (a)); \
	} \
	else \
		asm("btst.b %1,0(%3,%2.w); sne.b %0" : "=d" (__result) : "di" (n), "da" (offset), "a" (a)); \
	__result;})
	
#define EXT_GETPIX(p, x, y) EXT_GETPIX_AN(p, EXT_PIXOFFSET(x,y), ~(x))

//END pixel state grabing definition

void Fastmemcpy(void* src,void* dest, long nbloop) __attribute__((__stkparm__));  // C prototype	Function written by me
void RotateSprite8_R(unsigned char *srcSprite asm("%a0"),unsigned char *destSprite asm("%a1"),short height,short originX asm("%d1"),short originY asm("%d2"),long degreesClockwise asm("%d0"));
void SpriteX8Get_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),void *src asm("%a1"),unsigned char *dest asm("%a0"),short bytewidth asm("%d3"));
void SpriteX8_OR(short x,short y,short h,unsigned char *sprt,short w,void *dest) __attribute__((__stkparm__));
void SpriteX8_XOR(short x,short y,short h,unsigned char *sprt,short w,void *dest) __attribute__((__stkparm__));
void SpriteX8_AND(short x,short y,short h,unsigned char *sprt,short w,void *dest) __attribute__((__stkparm__));
void SpriteX8_RPLC_R(short x asm("%d0"),short y asm("%d1"),short h asm("%d2"),const unsigned char *sprt asm("%a1"),short w asm("%d3"),void *dest asm("%a0")) __attribute__((__regparm__));
void FastClearScreen_R(void *plane asm("%a0"));
void FastOutlinedCircle_DRAW_R(void *plane asm("%a0"),unsigned short xcenter asm("%d0"),unsigned short ycenter asm("%d1"),unsigned short radius asm("%d2"));
void FastOutlinedCircle_ERASE_R(void *plane asm("%a0"),unsigned short xcenter asm("%d0"),unsigned short ycenter asm("%d1"),unsigned short radius asm("%d2"));
void ClipFastOutlinedCircle_INVERT_R(void *plane asm("%a0"),unsigned short xcenter asm("%d0"),unsigned short ycenter asm("%d1"),unsigned short radius asm("%d2"));

void DrawSpan_REVERSE_R(short x1 asm("%d0"), short x2 asm("%d1"), void * addr asm("%a0"));
void DrawSpan_OR_R(short x1 asm("%d0"), short x2 asm("%d1"), void * addr asm("%a0"));
void DrawSpan_XOR_R(short x1 asm("%d0"), short x2 asm("%d1"), void * addr asm("%a0"));

void ClipFastFilledCircle_R(void *plane asm("%a0"),short xcenter asm("%d0"),short ycenter asm("%d1"),short radius asm("%d2"), void(*drawfunc)(short x1 asm("%d0"), short x2 asm("%d1"), void * addr asm("%a0")) asm("%a2"));

#define EXT_SETPIX_AN(a, offset, n) ({if(__builtin_constant_p(offset)) \
	{	\
		if(__builtin_constant_p(a))	\
			asm("bset.b %0,%c1" : : "di" (n), "dai" ((offset)+(unsigned char*)(a)));	\
		else	\
			if (offset !=0) \
				asm("bset.b %0,%c1(%2)" : : "di,di" (n), "i,\?\?\?\?!g" (offset), "a,a" (a));	\
			else \
				asm("bset.b %0,(%1)" : : "di" (n), "a" (a));	\
	}	\
	else	\
		asm("bset.b %0,0(%2,%1.w)" : : "di" (n), "da" (offset), "a" (a));	\
	})

#define EXT_CLRPIX_AN(a, offset, n) ({if(__builtin_constant_p(offset)) \
	{	\
		if(__builtin_constant_p(a))	\
			asm("bclr.b %0,%c1" : : "di" (n), "dai" ((offset)+(unsigned char*)(a)));	\
		else	\
			if (offset !=0) \
				asm("bclr.b %0,%c1(%2)" : : "di,di" (n), "i,\?\?\?\?!g" (offset), "a,a" (a));	\
			else \
				asm("bclr.b %0,(%1)" : : "di" (n), "a" (a));	\
	}	\
	else	\
		asm("bclr.b %0,0(%2,%1.w)" : : "di" (n), "da" (offset), "a" (a));	\
	})

#define EXT_XORPIX_AN(a, offset, n) ({if(__builtin_constant_p(offset)) \
	{ \
		if(__builtin_constant_p(a)) \
			asm("bchg.b %0,%c1" : : "di" (n), "dai" ((offset)+(unsigned char*)(a))); \
		else \
			if (offset !=0) \
				asm("bchg.b %0,%c1(%2)" : : "di,di" (n), "i,\?\?\?\?!g" (offset), "a,a" (a)); \
			else \
				asm("bchg.b %0,(%1)" : : "di" (n), "a" (a)); \
	} \
	else \
		asm("bchg.b %0,0(%2,%1.w)" : : "di" (n), "da" (offset), "a" (a)); \
	})

#define EXT_SETPIX(p, x, y) EXT_SETPIX_AN(p, EXT_PIXOFFSET(x,y), ~(x))
#define EXT_CLRPIX(p, x, y) EXT_CLRPIX_AN(p, EXT_PIXOFFSET(x,y), ~(x))
#define EXT_XORPIX(p, x, y) EXT_XORPIX_AN(p, EXT_PIXOFFSET(x,y), ~(x))
