#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <inttypes.h>
#include "bvdd.h"

int main(int argc, char **argv)
{
    int fd;
    uint32_t *mapped;

    fd = open("/home/zaurus/.dev_bvdd", O_RDWR);
    if (fd < 0) {
	perror("open");
	return 1;
    }

    if (ioctl(fd, BVDD_IOCTL_SETUP_VRAM, (640 * 480 * 8)) < 0) {
	perror("ioctl(BVDD_IOCTL_SETUP_VRAM)");
	close(fd);
	return 1;
    }

#if 0
    mapped = mmap(0, 320 * 240 * 2/*len*/, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
		  BVDD_VRAM_OFFSET_USER/*offset*/);
    if (mapped == MAP_FAILED) {
	perror("mmap");
	close(fd);
	return 1;
    }
#endif

    {
	bvdd_frame_t frame;
	frame.format = BVDD_FORMAT_YUV420;
	frame.width = 240;
	frame.height = 320;
	frame.x = 0;
	frame.y = 0;
	frame.offset = BVDD_VRAM_OFFSET_USER;
	frame.u_offset = frame.offset + (320 * 240);
	frame.v_offset = frame.u_offset + ((320 * 240) / 4);
	ioctl(fd, BVDD_IOCTL_SETUP_OVERLAY2_FRAME, &frame);
    }

    sleep(1);

    ioctl(fd, BVDD_IOCTL_DEBUG);

    close(fd);
    return 0;
}
