/***************************************************************************

	video.c

	PSP video control functions. (support 16bit color only)

***************************************************************************/

#ifndef PSP_VIDEO_H
#define PSP_VIDEO_H

#define SCR_WIDTH	480
#define SCR_HEIGHT	272
#define BUF_WIDTH	512
#define	FRAMESIZE	(BUF_WIDTH * SCR_HEIGHT * 2)

#define SLICE_SIZE		64 // change this to experiment with different page-cache sizes
#define TEXTURE_FLAGS	(GU_TEXTURE_16BIT | GU_COLOR_5551 | GU_VERTEX_16BIT | GU_TRANSFORM_2D)

#define MAKECOL15(r, g, b)	(((b & 0xf8) << 7) | ((g & 0xf8) << 2) | ((r & 0xf8) >> 3))
#define GETR15(col)			(((col << 3) & 0xf8) | ((col >>  2) & 0x07))
#define GETG15(col)			(((col >> 2) & 0xf8) | ((col >>  7) & 0x07))
#define GETB15(col)			(((col >> 7) & 0xf8) | ((col >> 12) & 0x07))

#define COLOR_BLACK		MAKECOL15(  0,  0,  0)
#define COLOR_RED		MAKECOL15(255,  0,  0)
#define COLOR_GREEN		MAKECOL15(  0,255,  0)
#define COLOR_BLUE		MAKECOL15(  0,  0,255)
#define COLOR_YELLOW	MAKECOL15(255,255,  0)
#define COLOR_PURPLE	MAKECOL15(255,  0,255)
#define COLOR_CYAN		MAKECOL15(  0,255,255)
#define COLOR_WHITE		MAKECOL15(255,255,255)
#define COLOR_GLAY		MAKECOL15(127,127,127)
#define COLOR_DRED		MAKECOL15(127,  0,  0)
#define COLOR_DGREEN	MAKECOL15(  0,127,  0)
#define COLOR_DBLUE		MAKECOL15(  0,  0,127)
#define COLOR_DYELLOW	MAKECOL15(127,127,  0)
#define COLOR_DPURPLE	MAKECOL15(127,  0,127)
#define COLOR_DCYAN		MAKECOL15(  0,127,127)
#define COLOR_DGRAY		MAKECOL15( 63, 63, 63)

struct Vertex
{
	u16 u, v;
	u16 color;
	s16 x, y, z;
};

struct rectangle
{
	int min_x;
	int max_x;
	int min_y;
	int max_y;
};

typedef struct rect_t
{
	int left;
	int top;
	int right;
	int bottom;
} RECT;


extern u32 gulist[262144];
extern int show_frame;
extern int draw_frame;
extern int work_frame;
extern int tex_frame;
extern RECT full_rect;

void video_init(void);
void video_exit(void);
u16 *video_frame_addr(int frame, int x, int y);
void video_clear_screen(void);
void video_clear_frame(int frame);
void video_wait_vsync(void);
void video_flip_screen(int vsync);
void video_copy_rect(int src, int dst, RECT *src_rect, RECT *dst_rect);

#endif /* PSP_VIDE_H */
