From 46ab351125c93564e17aacce420069f865188737 Mon Sep 17 00:00:00 2001
From: sparky4 <sparky4@cock.li>
Date: Tue, 14 Feb 2017 11:38:49 -0600
Subject: [PATCH] too tired to continue

---
 data/16.pal        | Bin 768 -> 768 bytes
 data/G.PAL         | Bin 768 -> 768 bytes
 src/lib/16_map.c   |   2 +-
 src/lib/16_tdef.h  |  92 +++++++++++++++++++++++----------------------
 src/lib/16_vl.c    |  17 ++-------
 src/lib/16_vlpal.c |  10 ++---
 src/lib/bitmap.c   |  13 ++++---
 src/lib/scroll16.c |  43 ++++++++++-----------
 src/maptest.c      |  20 ++++++----
 9 files changed, 97 insertions(+), 100 deletions(-)

diff --git a/data/16.pal b/data/16.pal
index eaf5208550ce2b2d7a255488e2de6b8d22afb6c8..cb6f0aef37b2280a7cac68a10dc99108348f0789 100755
GIT binary patch
delta 17
YcmZo*Yharo!OY0WxKZ&w(?kO{040h9H2?qr

delta 13
UcmZo*Yharou~G3p(?kPK03Lk=G5`Po

diff --git a/data/G.PAL b/data/G.PAL
index 8092380af954e11b165eae773d83f03429619756..07edf768ed7f6efd53e88d7cc113aba28ab309f6 100755
GIT binary patch
delta 11
ScmZo*YhYt$U|`trmk9t4m;%25

delta 12
TcmZo*Yhc^R{FjNDfq?-47bOD2

diff --git a/src/lib/16_map.c b/src/lib/16_map.c
index 37179ab7..b17eb932 100755
--- a/src/lib/16_map.c
+++ b/src/lib/16_map.c
@@ -296,7 +296,7 @@ void extract_map(const char *js, jsmntok_t *t, size_t count, map_t *map) {
 				if(jsoneq(js, &(t[i]), "image") == 0) {
 					map->MAPTILESPTK = malloc(sizeof(tiles_t));
 					s = remove_ext((char *)js+t[i+1].start, '.', '/');
-					strcpy(map->MAPTILESPTK->imgname, s);
+					strcpy(map->MAPTILESPTK->tileset.imgname, s);
 					//And move to vrs, probably
 //					bp = bitmapLoadPcx("data/ed.pcx");
 //					map->MAPTILESPTK->btdata = &bp;
diff --git a/src/lib/16_tdef.h b/src/lib/16_tdef.h
index 38fd2260..4700625e 100755
--- a/src/lib/16_tdef.h
+++ b/src/lib/16_tdef.h
@@ -48,14 +48,44 @@ typedef struct {
 	word offset;
 } bitmap_t;
 
+//from 16_sprit.h
+#ifdef	__WATCOMC__
+typedef struct sprite
+{
+	// VRS container from which we will extract animation and image data
+	struct vrs_container *spritesheet;
+	// Container for a vrl sprite
+	struct vrl_container *sprite_vrl_cont;
+	// Current sprite id
+	int curr_spri_id;
+	// Index of a current sprite in an animation sequence
+	int curr_anim_spri;
+	// Current animation sequence
+	struct vrs_animation_list_entry_t *curr_anim_list;
+	// Index of current animation in relevant VRS offsets table
+	int curr_anim;
+	// Delay in time units untill we should change sprite
+	int delay;
+	// Position of sprite on screen
+	int x, y;
+} sprite_t;
+#endif
+
 typedef struct {
-	byte far **data;
-	word ntiles;   /* the number of tiles */
-	word twidth;   /* width of the tiles */
-	word theight;  /* height of the tiles */
-	byte *palette; /* palette for the tile set */
+	//byte far **data;
+//#ifdef	__WATCOMC__
+	//sprite_t *spri;
+//#endif
+	bitmap_t far *data;	// actual tileset info
+//in the bitmap_t
+//	byte *palette;		// palette for the tile set
+	word ntiles;			// the number of tiles
+	word twidth;		// width of the tiles
+	word theight;		// height of the tiles
+	byte	imgname[8];		// image filename of tileset
 } tileset_t;
 
+//not currently using
 typedef struct {
 	byte far *plane[4];	// 4 planes of image data
 	word width;			// width of the image (spread across 4 planes)
@@ -64,25 +94,20 @@ typedef struct {
 	byte *palette;
 } planar_buf_t;
 
-//TODO: 16_mm and 16_ca must handle this
+//tile properties
 typedef struct {
-	bitmap_t far *data;		//old
-	//planar_buf_t far *data;	//old
+	//bitmap_t far *btdata;		//old
+	tileset_t	tileset;			//new
 	word tileHeight, tileWidth;
-	unsigned int rows, cols;
-// 	#ifdef __DEBUG__
-// 	boolean debug_text;	//show the value of the tile! wwww
-// 	byte *debug_data;
-// 	#endif
-	byte	imgname[8];		//image file of tileset
+	word rows, cols;
 } tiles_t;
 
 //TODO: 16_mm and 16_ca must handle this
 //TODO: add variables from 16_ca
+#define MAPLAYERS 4
 //#define __NEWMAPTILEDATAVARS__
 
 #ifdef __NEWMAPTILEDATAVARS__
-#define MAPLAYERS 4
 #define MAPTILESPTR		layertile[0]
 #define MAPTILESPTK		layertile[k]
 #define MAPDATAPTR		layerdata[0]
@@ -97,14 +122,14 @@ typedef struct {
 	//long		planestart[3];
 	//unsigned	planelength[3];
 #ifndef __NEWMAPTILEDATAVARS__
-	byte *data;			//TODO: 16_mm and 16_ca must handle this
-	tiles_t *tiles;		//TODO: 16_mm and 16_ca must handle this
+	byte		*data;			//TODO: 16_mm and 16_ca must handle this
+	tiles_t		*tiles;		//TODO: 16_mm and 16_ca must handle this
 #else
-	byte * far *layerdata;	//TODO: 16_mm and 16_ca must handle this
-	tiles_t far *layertile[MAPLAYERS];	//TODO: 16_mm and 16_ca must handle this
+	byte far	*layerdata[MAPLAYERS];	//mapindex for specific layer
+	tiles_t far	*layertile[MAPLAYERS];
 #endif
 	int width, height;		//this has to be signed!
-	byte name[16];
+	byte name[16];		//mapname/maptitle
 } map_t;
 
 typedef struct{
@@ -116,12 +141,12 @@ typedef struct{
 	sword tilemidposscreeny;	/* middle tile y position */	/* needed for scroll system to work accordingly */
 	sword tileplayerposscreenx;	/* player position on screen */	/* needed for scroll and map system to work accordingly */
 	sword tileplayerposscreeny;	/* player position on screen */	/* needed for scroll and map system to work accordingly */
-} tileinfo_t;
+} pagetileinfo_t;
 
 typedef struct {
 	nibble/*word*/ id;	/* the Identification number of the page~ For layering~ */
 	byte far* data;	/* the data for the page */
-	tileinfo_t	ti;
+	pagetileinfo_t	ti;
 	word dx;		/* col we are viewing on virtual screen (on page[0]) */	/* off screen buffer on the left size */
 	word dy;		/* row we are viewing on virtual screen (on page[0]) */	/* off screen buffer on the top size */
 	word sw;		/* screen width */	/* resolution */
@@ -137,29 +162,6 @@ typedef struct {
 	sword delta;			// How much should we shift the page for smooth scrolling
 } page_t;
 
-//from 16_sprit.h
-#ifdef	__WATCOMC__
-typedef struct sprite
-{
-	// VRS container from which we will extract animation and image data
-	struct vrs_container *spritesheet;
-	// Container for a vrl sprite
-	struct vrl_container *sprite_vrl_cont;
-	// Current sprite id
-	int curr_spri_id;
-	// Index of a current sprite in an animation sequence
-	int curr_anim_spri;
-	// Current animation sequence
-	struct vrs_animation_list_entry_t *curr_anim_list;
-	// Index of current animation in relevant VRS offsets table
-	int curr_anim;
-	// Delay in time units untill we should change sprite
-	int delay;
-	// Position of sprite on screen
-	int x, y;
-} sprite_t;
-#endif
-
 //newer structs
 typedef	struct
 {
diff --git a/src/lib/16_vl.c b/src/lib/16_vl.c
index 881239de..71c5667d 100755
--- a/src/lib/16_vl.c
+++ b/src/lib/16_vl.c
@@ -689,18 +689,7 @@ modexLoadPalFile(byte *filename, byte **palette) {
 
 void VL_LoadPalFile(const char *filename, byte *palette)
 {
-	int fd;
-
-	fd = open(filename,O_RDONLY|O_BINARY);
-	if (fd >= 0) {
-		word i;
-
-		read(fd,palette,	PAL_SIZE);
-		close(fd);
-
-		vga_palette_lseek(0);
-		for (i=0;i < 256;i++) vga_palette_write(palette[(i*3)+0]>>2,palette[(i*3)+1]>>2,palette[(i*3)+2]>>2);
-	}
+	VL_LoadPalFilewithoffset(filename, palette, 0);
 }
 
 void VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o)
@@ -714,8 +703,8 @@ void VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o)
 		read(fd,palette,	PAL_SIZE);
 		close(fd);
 
-		vga_palette_lseek(o);
-		for (i=o;i < 256-o;i++) vga_palette_write(palette[(i*3)+0]>>2,palette[(i*3)+1]>>2,palette[(i*3)+2]>>2);
+		vga_palette_lseek(1+o);
+		for (i=o;i < 255-o;i++) vga_palette_write(palette[(i*3)+0]>>2,palette[(i*3)+1]>>2,palette[(i*3)+2]>>2);
 	}
 }
 
diff --git a/src/lib/16_vlpal.c b/src/lib/16_vlpal.c
index 2f155f03..db0f19d6 100755
--- a/src/lib/16_vlpal.c
+++ b/src/lib/16_vlpal.c
@@ -32,7 +32,7 @@ void modexchkcolor(imgtestpal_t *bmp, word *q, word *a, word *aa, word *z, word
 		modexPalSave(pal);
 		CHKCOLDBGOUT1
 		//check palette for dups
-		for(; (*z)<PAL_SIZE; (*z)+=3)
+		for(; (*z)<PAL_SIZE-3; (*z)+=3)
 		{
 			CHKCOLDBGOUT2
 			//if((*z)%3==0)
@@ -99,7 +99,7 @@ VL_palette(imgtestpal_t *bmp, byte *p, word *i, word qp, word aqoffset)
 	word w=0;
 	word q=0;
 	word qq=0;
-	static word a[PAL_SIZE];	//palette array of change values!
+	static word a[PAL_SIZE-3];	//palette array of change values!
 	word z=0, aq=0, aa=0, pp=0;
 
 	//modexWaitBorder();
@@ -107,7 +107,7 @@ VL_palette(imgtestpal_t *bmp, byte *p, word *i, word qp, word aqoffset)
 	if((*i)==0)
 	{
 		memset(a, -1, sizeof(a));
-		outp(PAL_WRITE_REG, 0);  /* start at the beginning of palette */
+		outp(PAL_WRITE_REG, 1);  /* start at the beginning of palette */
 	}
 	else if(qp==0)
 	{
@@ -124,9 +124,9 @@ VL_palette(imgtestpal_t *bmp, byte *p, word *i, word qp, word aqoffset)
 #endif
 		outp(PAL_WRITE_REG, qq);  /* start at the beginning of palette */
 	}
-	if((*i)<PAL_SIZE && w==0)
+	if((*i)<PAL_SIZE-3 && w==0)
 	{
-		for(; (*i)<PAL_SIZE; (*i)++)
+		for(; (*i)<PAL_SIZE-3; (*i)++)
 		{
 			//if(i%3==0 && (p[i+5]==p[i+4] && p[i+4]==p[i+3] && p[i+3]==p[i+2] && p[i+2]==p[i+1] && p[i+1]==p[i] && p[i+5]==p[i]))
 //____		  if((qp>0)&&((*i)-q)%3==0 && (p[((*i)-q)]==p[((*i)-q)+3] && p[((*i)-q)+1]==p[((*i)-q)+4] && p[((*i)-q)+2]==p[((*i)-q)+5])) outp(PAL_DATA_REG, p[(*i)-q]); else
diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c
index 22bad981..b42204aa 100755
--- a/src/lib/bitmap.c
+++ b/src/lib/bitmap.c
@@ -160,6 +160,7 @@ bitmapLoadPcx(char *filename, global_game_variables_t *gv) {
 }
 
 //TODO: update!!
+/*
 tileset_t
 bitmapLoadPcxTiles(char *filename, word twidth, word theight) {
 	tileset_t ts;
@@ -167,33 +168,33 @@ bitmapLoadPcxTiles(char *filename, word twidth, word theight) {
 	bitmap_t result;
 	int i;
 
-	/* open the PCX file for reading */
+	// open the PCX file for reading
 	file = fopen(filename, "rb");
 	if(!file) {
 		printf("Could not open %s for reading.\n", filename);
 		exit(-2);
 	}
 
-	/* load the first part of the pcx file */
+	// load the first part of the pcx file
 	loadPcxStage1(file, &result);
 
-	/* get the number of tiles and set up the result structure */
+	// get the number of tiles and set up the result structure
 	ts.twidth = twidth;
 	ts.theight = theight;
 	ts.ntiles = (result.width/twidth) * (result.height/theight);
 	ts.palette = result.palette;
 
-	/* allocate the pixel storage for the tiles */
+	// allocate the pixel storage for the tiles
 	ts.data = _fmalloc(sizeof(byte*) * ts.ntiles);
 	//ts.data[0] = malloc(sizeof(byte) * ts.ntiles * twidth * theight);
 	for(i=1; i < ts.ntiles; i++) {
 		ts.data[i] = ts.data[i-1] + twidth * theight;
 	}
 
-	/* finish off the file */
+	// finish off the file
 	loadPcxPalette(file, &result);
 
 	fclose(file);
 
 	return ts;
-}
+}*/
diff --git a/src/lib/scroll16.c b/src/lib/scroll16.c
index 9a4708ab..e60a8b97 100755
--- a/src/lib/scroll16.c
+++ b/src/lib/scroll16.c
@@ -563,42 +563,43 @@ void ZC_mapredraw(map_view_t *mv, int tx, int ty)
 void near
 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
 {
-	word rx;
-	word ry;
+	word rx, ry;
 	//word textx=0, texty=0;
 	//if(i==0) i=2;
-	if(i==0)
+	switch(i)
 	{
+		case 0:
 		//wwww
-		modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 1); //currently the over scan color!
-	}
-	else
-	{
-		rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
-		ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
+			modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
+		break;
+		case 1:
+			rx = (((i-1) % ((t->tileset.data->width)/t->tileWidth)) * t->tileWidth);
+			ry = (((i-1) / ((t->tileset.data->height)/t->tileHeight)) * t->tileHeight);
+//			rx = (((i-1) % ((t->spri->sprite_vrl_cont->vrl_header->width)/t->tileWidth)) * t->tileWidth);
+//			ry = (((i-1) / ((t->spri->sprite_vrl_cont->vrl_header->height)/t->tileHeight)) * t->tileHeight);
 ////0000printf("i=%d\n", i);
-#ifdef __DEBUG_MAP__
-		switch(dbg_maptext)
-		{
-			case 0:
-#endif
 #ifndef TILERENDER
-				if(!pagenorendermap) modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, i+1);
+			if(!pagenorendermap) modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, i+1);
 #else
-				modexDrawBmpRegion		(page, x, y, rx, ry, t->tileWidth, t->tileHeight, i);
-				/* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
-				//draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
-				//modexDrawBmpRegion	(page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
+			//modexDrawBmpRegion		(page, x, y, rx, ry, t->tileWidth, t->tileHeight, i);
+			/* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
+			//draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
+			//modexDrawBmpRegion	(page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
+			//drawmap here
 #endif
 #ifdef __DEBUG_MAP__
+		switch(dbg_maptext)
+		{
+			case 0:
+
 			break;
 			case 1:
-				if(!pagenorendermap) modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, i);
 				sprintf(global_temp_status_text2, "%d", i);
-				modexprint(page, x, y, 1, 1, 2, global_temp_status_text2);
+				modexprint(page, x+8, y+8, 1, 1, 2, global_temp_status_text2);
 			break;
 		}
 #endif
+		break;
 	}
 }
 
diff --git a/src/maptest.c b/src/maptest.c
index f426b2c6..696f9b73 100755
--- a/src/maptest.c
+++ b/src/maptest.c
@@ -31,7 +31,7 @@ main(int argc, char *argv[])
 	map_t map;
 #ifdef DUMP
 #ifdef DUMP_MAP
-	short i;
+	short i,k;
 #endif
 #endif
 	char *fmt = "Memory available = %u\n";
@@ -58,15 +58,19 @@ main(int argc, char *argv[])
 	fprintf(stdout, "map.height=	%d\n", map.height);
 	#ifdef DUMP_MAP
 	//if(map.width*map.height != 1200)
-	for(i=0; i<(map.width*map.height); i++)
+	for(k=0;k<MAPLAYERS;k++)
 	{
-		//fprintf(stdout, "%04d[%02d]", i, map.data[i]);
-		fprintf(stdout, "%c", map.MAPDATAPTR[i]+44);
-		if(!((i+1)%map.width)){
-			//fprintf(stdout, "[%d]", i);
-			fprintf(stdout, "\n"); }
+		for(i=0; i<(map.width*map.height); i++)
+		{
+			//fprintf(stdout, "%04d[%02d]", i, map.data[i]);
+			fprintf(stdout, "%c", map.MAPDATAPTR[i]+44);
+			if(!((i+1)%map.width)){
+				//fprintf(stdout, "[%d]", i);
+				fprintf(stdout, "\n"); }
+		}
+		fprintf(stdout, "\n");
+		getch();
 	}
-	fprintf(stdout, "\n");
 	#else
 	//fprintf(stderr, "contents of the buffer\n[\n%s\n]\n", (gvar.ca.camap.mapsegs));
 	#endif
-- 
2.39.5