#ifndef GFX_H
#define GFX_H

#include "libsys.h"

#define	GFX_NUM_FRAME_BUFFERS	2
#define	GFX_FRAME_NOSYNC		0
#define	GFX_FRAME_SYNC			1

// -------------------------------------------------------------
// Types
// -------------------------------------------------------------
typedef struct _sbox_t
{
	UINT32 w, h;
} box_t;

typedef struct _srect_t
{
	UINT32 xmin, xmax;
	UINT32 ymin, ymax;
} rect_t;

typedef struct _svga_hw_t
{
	UINT32 volatile pVGA_ctrl;			// 0xA0030000	// R/W
	UINT32 volatile pVGA_ascii;			// 0xA0030004	// R/W
	UINT32 volatile pVGA_posx;			// 0xA0030008	// R/W
	UINT32 volatile pVGA_posy;			// 0xA003000C	// R/W
	UINT32 volatile pVGA_cgcol;			// 0xA0030010	// R/W
	UINT32 volatile pVGA_res;			// 0xA0030014	// RO
	UINT32 volatile pVGA_front;			// 0xA0030018	// R/W
	UINT32 volatile pVGA_back;			// 0xA003001C	// R/W
	UINT32 volatile pVGA_src0;			// 0xA0030020	// R/W
	UINT32 volatile pVGA_src0_last;		// 0xA0030024	// R/W
	UINT32 volatile pVGA_src0_dimx;		// 0xA0030028	// R/W
	UINT32 volatile pVGA_src0_res;		// 0xA003002C	// R/W
	UINT32 volatile pVGA_src1;			// 0xA0030030	// R/W
	UINT32 volatile pVGA_src1_last;		// 0xA0030034	// R/W
	UINT32 volatile pVGA_src1_dimx;		// 0xA0030038	// R/W
	UINT32 volatile pVGA_src1_res;		// 0xA003003C	// R/W
	UINT32 volatile pVGA_src2;			// 0xA0030040	// R/W
	UINT32 volatile pVGA_src2_last;		// 0xA0030044	// R/W
	UINT32 volatile pVGA_src2_dimx;		// 0xA0030048	// R/W
	UINT32 volatile pVGA_src2_res;		// 0xA003004C	// R/W
	UINT32 volatile pVGA_dst;			// 0xA0030050	// R/W
	UINT32 volatile pVGA_dst_last;		// 0xA0030054	// R/W
	UINT32 volatile pVGA_dst_dimx;		// 0xA0030058	// R/W
	UINT32 volatile pVGA_dst_res;		// 0xA003005C	// R/W
	UINT32 volatile pVGA_nx;			// 0xA0030060	// R/W
	UINT32 volatile pVGA_ny;			// 0xA0030064	// R/W

} vga_hw_t;

typedef struct _sbuf_t
{
	UINT32 *pFB;
	struct _sbuf_t *pNext;
	struct _sbuf_t *pLast;
	UINT32 is_dirty;
	rect_t rect;
	UINT32 w, h;
	vga_hw_t *regs;
} buf_t;

typedef struct _sgfx_t
{
	UINT32 w, h;
	buf_t *pBuf;
	UINT32 *pBG;
	vga_hw_t *regs;

} gfx_t;

// -------------------------------------------------------------
// Functions
// -------------------------------------------------------------
void __gfx_block_set_8(UINT32* pDst, UINT32 value);
void __gfx_block_copy_8(UINT32* pDst, UINT32* pSrc);
void __gfx_copy_32(UINT32* pDst, UINT32* pSrc, UINT32 nblocks);
void GFX_init(gfx_t *pObj);
void GFX_frame(gfx_t *pObj, UINT32 sync_mode);
void GFX_show(gfx_t *pObj);
void GFX_copy_front2back(gfx_t *pObj);
void GFX_get_FB_front(gfx_t *pObj, UINT32 **ppFB);
void box_create(box_t *pObj, UINT32 w, UINT32 h);
void GFX_restore(gfx_t *pObj, box_t *pBox, UINT32 posx, UINT32 posy);
void GFX_box_draw(gfx_t *pObj, box_t *pBox, UINT32 posx, UINT32 posy, UINT32 color);
void GFX_box_draw_bg(gfx_t *pObj, box_t *pBox, UINT32 posx, UINT32 posy, UINT32 color);

#endif // GFX_H
