/*
 * FILE				: vga.c
 * DESCRIPTION		: This file is 3-wire vga driver for niosii.
 * Author			: XiaomaGee@Gmail.com
 * Copyright		:
 *
 * History
 * --------------------
 * Rev	: 0.00
 * Date	: 03/08/2012
 *
 * create.
 * --------------------
 */

//---------------- Include files ------------------------//
#include "..\include\vga.h"
#include <stdio.h>
#include <stdlib.h>
#include "altera_avalon_pio_regs.h"
#include "system.h"
#include "io.h"

//---------------- Function Prototype -------------------//
static int initialize(void);
static int on(void);
static int off(void);
static int clear( int color);
static int dot(int x, int y , int color);
static int get_dot(int x, int y);


//---------------- Variable -----------------------------//
VGA_T vga = {
	.initialize = initialize,
	.clear = clear,
	.dot = dot,
	.get_dot = get_dot,
	.on = on,
	.off = off
};

unsigned char vga_buffer[VGA_HEIGHT*VGA_WIDTH];

//-----------------Function------------------------------//
/*
 * Name				: initialize
 * Description		: ---
 * Author			: XiaomaGee.
 *
 * History
 * ----------------------
 * Rev	: 0.00
 * Date	: 03/08/2012
 *
 * create.
 * ----------------------
 */
static int initialize(void)
{
 IOWR(VGA_3BITS_BASE,0,(unsigned long int)vga_buffer);

	return 0;
}
/*
 * Name				: on
 * Description		: ---
 * Author			: XiaomaGee.
 *
 * History
 * ----------------------
 * Rev	: 0.00
 * Date	: 03/08/2012
 *
 * create.
 * ----------------------
 */
static int on(void)
{
 IOWR(VGA_3BITS_BASE,1,1);

	return 0;
}
/*
 * Name				: on
 * Description		: ---
 * Author			: XiaomaGee.
 *
 * History
 * ----------------------
 * Rev	: 0.00
 * Date	: 03/08/2012
 *
 * create.
 * ----------------------
 */
static int off(void)
{
 IOWR(VGA_3BITS_BASE,1,0);

	return 0;
}
/*
 * Name				: clear
 * Description		: ---
 * Author			: XiaomaGee.
 *
 * History
 * -----------------------
 * Rev	: 0.00
 * Date	: 03/05/2012
 *
 * create.
 * ----------------------
 */
static
int clear(int color)
{
		int i,j;

		for(i = 0; i < VGA_HEIGHT; i ++)
				for(j = 0; j < VGA_WIDTH; j ++)DOT(j,i,color);

		return 0;
}
/*
 * Name				: dot
 * Description		: ---
 * Author			: XiaomaGee.
 *
 * History
 * ----------------------
 * Rev	: 0.00
 * Date	: 03/08/2012
 *
 * create.
 * ----------------------
 */
__inline static int dot(int x, int y, int color)
{

	DOT(x,y,color);

	return 0;
}
/*
 * Name				: get_dot
 * Description		: ---
 * Author			: XiaomaGee.
 *
 * History
 * ----------------------
 * Rev	: 0.00
 * Date	: 03/08/2012
 *
 * create.
 * ----------------------
 */
static int get_dot(int x, int y)
{
	return GET_DOT(x,y);
}
