#include "iff.h"
#include <fcntl.h> 
#include <stdlib.h>
#include <stdio.h>
#include <vga.h>
#include <vgamouse.h>


unsigned char Pal0[] = {0,0,0,0,0,0x2A,0,0x2A,0};
unsigned char Pal11[] = {0x15,0x3f,0x3f,0x3f,0x15,0x15,0x3f,0x15,0x3f};
unsigned char Pal15[] = {0x3f,0x3f,0x3f,0x3b,0x3b,0x3b,0x37,0x37,0x37};

void loadpalette()
{
int f;
int i;
unsigned char *pal;

	f = open("pal", O_RDONLY);
	pal = malloc(768);
	read(f, pal, 768);

	memcpy(pal, Pal0, 9);
	memcpy(&pal[0x21], Pal11, 9);
	memcpy(&pal[0x2d], Pal15, 9);

	for (i = 0; i < 256; i++) {
		vga_setpalette(i, pal[i*3], pal[(i*3)+1], pal[(i*3)+2]);
	}
	free(pal);
}

int w, h;

int main()
{
int i, j;
unsigned char *bmap;
unsigned char *d, *s;

	vga_setmode(G320x200x256);
	mouse_installed();
#if 0
	loadpalette();
#endif
	memset(graph_mem, 3, 64000);
	bmap = Readiff("mapedit.lbm");
	w = (*(short *)bmap);
	h = (*(short *)&bmap[2]);

	d = graph_mem;
	s = &bmap[4];
	for (i = 0; i < h; i++) {
		memcpy(d, s, w);
		d += 320;
		s += w;
	}

	while (1) {
	int button, r, c;

		if (vga_getkey() != 0)
			break;
		mouse_read_cursor(&button, &r, &c);
	}
	vga_setmode(TEXT);
	exit(0);

}

