From 0a79071b241fd133918bf178f5bd322368e4957c Mon Sep 17 00:00:00 2001
From: sparky4 <sparky4@cock.li>
Date: Fri, 27 Jan 2017 10:05:57 -0600
Subject: [PATCH] it is semi working the bg preservation wwww

---
 data/test.map      |  3 +--
 data/test.tmx      |  4 ++--
 src/0.c            |  2 +-
 src/lib/16_enti.c  | 29 +++++++++++++++++++++++++----
 src/lib/16_enti.h  |  4 ++--
 src/lib/16_sprit.c | 19 ++++++++-----------
 src/lib/16_tail.h  |  5 ++++-
 src/lib/16_tdef.h  |  6 ++++++
 src/lib/16_vl.c    |  9 +++++++++
 src/lib/16_vl.h    |  1 +
 src/lib/scroll16.c | 22 +++++++++++-----------
 src/lib/scroll16.h |  2 +-
 src/scroll.c       |  2 +-
 src/test.c         |  2 +-
 src/zcroll.c       |  6 ++++--
 15 files changed, 77 insertions(+), 39 deletions(-)

diff --git a/data/test.map b/data/test.map
index 81ae685c..04d87322 100755
--- a/data/test.map
+++ b/data/test.map
@@ -2,7 +2,7 @@
  "height":30,
  "layers":[
         {
-         "data":[1, 2, 3, 4, 0, 3, 3, 3, 3, 3, 3, 3, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 6, 7, 8, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 10, 11, 12, 4, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 13, 14, 15, 16, 0, 1, 1, 1, 5, 8, 1, 11, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10, 10],
          "height":30,
          "name":"bg",
          "opacity":1,
@@ -17,7 +17,6 @@
     {
 
     },
- "renderorder":"right-down",
  "tileheight":16,
  "tilesets":[
         {
diff --git a/data/test.tmx b/data/test.tmx
index cb3cd45a..306c6bc3 100755
--- a/data/test.tmx
+++ b/data/test.tmx
@@ -1,11 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<map version="1.0" orientation="orthogonal" renderorder="right-down" width="40" height="30" tilewidth="16" tileheight="16" backgroundcolor="#000000">
+<map version="1.0" orientation="orthogonal" width="40" height="30" tilewidth="16" tileheight="16" backgroundcolor="#000000">
  <tileset firstgid="1" name="wwww" tilewidth="16" tileheight="16">
   <image source="ed.png" width="64" height="64"/>
  </tileset>
  <layer name="bg" width="40" height="30">
   <data encoding="csv">
-1,2,3,4,0,3,3,3,3,3,3,3,3,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
+1,2,3,4,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 5,6,7,8,0,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 9,10,11,12,4,1,0,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
 13,14,15,16,0,1,1,1,5,8,1,11,11,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
diff --git a/src/0.c b/src/0.c
index 2d55bcdf..31d1952e 100755
--- a/src/0.c
+++ b/src/0.c
@@ -83,7 +83,7 @@ int main(int argc,char **argv)
 
 	IN_Startup();
 	IN_Default(0,&player,ctrl_Keyboard1);
-	EN_initplayer(&player, 0);
+	EN_initplayer(&player, 0, &gvar.video);
 
 	/* setup camera and screen~ */
 	modexHiganbanaPageSetup(&gvar.video);
diff --git a/src/lib/16_enti.c b/src/lib/16_enti.c
index 1c89d9b7..cb05a46a 100755
--- a/src/lib/16_enti.c
+++ b/src/lib/16_enti.c
@@ -22,13 +22,15 @@
 
 #include "src/lib/16_enti.h"
 
-void EN_initentity(entity_t *enti)
+void EN_initentity(entity_t *enti, video_t *video)
 {
+	unsigned int i,o,o2,w,h;
 	//tx and ty inited by map
 	enti->x = enti->tx*TILEWH;
 	enti->y = enti->ty*TILEWH;
 	enti->triggerx = enti->tx;
-	enti->triggery = enti->ty+1;
+	enti->triggery = enti->ty+1;	//south
+
 	enti->q = 1;
 	enti->d =2;
 	enti->hp=4;
@@ -38,12 +40,31 @@ void EN_initentity(entity_t *enti)
 	enti->pred = enti->d;
 	enti->overdraww=0;
 	enti->overdrawh=4;
+
+// 	VL_Initofs(video);
+
+// 	modexClearRegion(&video->page[0], enti->x, enti->y, 16, 16, 2);
+// 	modexClearRegion(&video->page[2], 0, 0, video->page[2].sw, video->page[2].sh, 45);
+// 	modexClearRegion(&video->page[3], 0, 0, video->page[3].sw, video->page[3].sh, 47);
+
+	video->ofs.pattern_ofs=(uint16_t)video->page[0].data;
+	video->ofs.offscreen_ofs=(uint16_t)video->page[3].data;
+	w = (enti->x + 24) & (~3);
+	h = enti->y + 32;
+
+	// block copy pattern to where we will draw the sprite
+	vga_setup_wm1_block_copy();
+	o2 = video->ofs.offscreen_ofs;										//dest
+	o = video->ofs.pattern_ofs + (enti->y * video->page[0].stridew) + (enti->x >> 2);	// source
+	for (i=0;i < h;i++,o += video->page[0].stridew,o2 += (w >> 2)) vga_wm1_mem_block_copy(o2,o,w >> 2);
+	// must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally
+	vga_restore_rm0wm0();
 }
 
 //init player!
-void EN_initplayer(player_t *player, word pn)
+void EN_initplayer(player_t *player, word pn, video_t *video)
 {
-	EN_initentity(&player[pn].enti);
+	EN_initentity(&player[pn].enti, video);
 /*	player[0].info.x = player[0].tx;
 	player[0].info.xaxis = player[0].tx*TILEWH;
 	player[0].info.y = player[0].ty;
diff --git a/src/lib/16_enti.h b/src/lib/16_enti.h
index dc76c8a4..7f18b152 100755
--- a/src/lib/16_enti.h
+++ b/src/lib/16_enti.h
@@ -44,7 +44,7 @@
 // 	word spt;		// speed per tile
 // } entity_t;
 
-void EN_initentity(entity_t *enti);
-void EN_initplayer(player_t *player, word pn);
+void EN_initentity(entity_t *enti, video_t *video);
+void EN_initplayer(player_t *player, word pn, video_t *video);
 
 #endif
diff --git a/src/lib/16_sprit.c b/src/lib/16_sprit.c
index d9ecad99..66797e3d 100755
--- a/src/lib/16_sprit.c
+++ b/src/lib/16_sprit.c
@@ -99,16 +99,13 @@ void print_anim_ids(struct sprite *spri)
 void animate_spri(entity_t *enti, video_t *video)
 {
 #define INC_PER_FRAME if(enti->q&1) enti->persist_aniframe++; if(enti->persist_aniframe>4) enti->persist_aniframe = 1;
-	const unsigned int offscreen_ofs =	video->page[0].pagesize+video->page[1].pagesize;//(vga_state.vga_stride * vga_state.vga_height);
-	const unsigned int pattern_ofs =	0x10000UL - (uint16_t)video->page[2].data;//(vga_state.vga_stride * vga_state.vga_height);
-	unsigned int copy_ofs =			offscreen_ofs;
-	unsigned int display_ofs =		0x0000;
 	unsigned int i,o,o2; int j;
 	int x,y,rx,ry,w,h;
 
 	VGA_RAM_PTR omemptr = (VGA_RAM_PTR)video->page[0].data;// save original mem ptr
 	x=enti->spri->x;
 	y=enti->spri->y;
+	VL_Initofs(video);
 
 	// Depending on delay, update indices
 //#define FRAME1 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 48, player[pn].enti.dire, 24, 32,	PLAYERBMPDATAPTR);
@@ -116,11 +113,11 @@ void animate_spri(entity_t *enti, video_t *video)
 //#define FRAME3 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 0, player[pn].enti.dire, 24, 32,	PLAYERBMPDATAPTR);
 //#define FRAME4 modexDrawSpriteRegion(pip[(pip->video->p)].page, x, y, 24, player[pn].enti.dire, 24, 32,	PLAYERBMPDATAPTR); stand
 
-	/* copy active display (0) to offscreen buffer (0x4000) */
-	vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = vga_state.vga_stride;
+	// copy active display (0) to offscreen buffer (0x4000)
+	/*vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = vga_state.vga_stride;
 	vga_setup_wm1_block_copy();
 	vga_wm1_mem_block_copy(copy_ofs,	display_ofs,	vga_state.vga_stride * vga_state.vga_height);
-	vga_restore_rm0wm0();
+	vga_restore_rm0wm0();*/
 
 	switch(enti->spri->delay)
 	{
@@ -171,8 +168,8 @@ void animate_spri(entity_t *enti, video_t *video)
 
 	// block copy pattern to where we will draw the sprite
 	vga_setup_wm1_block_copy();
-	o2 = offscreen_ofs;
-	o = pattern_ofs + (ry * video->page[0].stridew) + (rx >> 2); // source offscreen		0x10000UL -
+	o2 = video->ofs.offscreen_ofs;
+	o = video->ofs.pattern_ofs + (ry * video->page[0].stridew) + (rx >> 2); // source offscreen
 	for (i=0;i < h;i++,o += video->page[0].stridew,o2 += (w >> 2)) vga_wm1_mem_block_copy(o2,o,w >> 2);
 
 	// must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally
@@ -180,7 +177,7 @@ void animate_spri(entity_t *enti, video_t *video)
 
 	// replace VGA stride with our own and mem ptr. then sprite rendering at this stage is just (0,0)
 	vga_state.vga_draw_stride = w >> 2;
-	vga_state.vga_graphics_ram = omemptr + offscreen_ofs;
+	vga_state.vga_graphics_ram = omemptr + video->ofs.offscreen_ofs;
 	}else{ rx=ry=w=h=0; vga_state.vga_graphics_ram = (VGA_RAM_PTR)video->page[0].data; }
 	vga_state.vga_draw_stride_limit = (video->page[0].width + 3 - x) >> 2;//round up
 
@@ -203,7 +200,7 @@ void animate_spri(entity_t *enti, video_t *video)
 
 	// block copy to visible RAM from offscreen
 	vga_setup_wm1_block_copy();
-	o = offscreen_ofs; // source offscreen
+	o = video->ofs.offscreen_ofs; // source offscreen
 	o2 = (ry * video->page[0].stridew) + (rx >> 2); // dest visible (original stride)
 	for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += video->page[0].stridew) vga_wm1_mem_block_copy(o2,o,w >> 2);
 	// must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally
diff --git a/src/lib/16_tail.h b/src/lib/16_tail.h
index 22d51178..984ad365 100755
--- a/src/lib/16_tail.h
+++ b/src/lib/16_tail.h
@@ -53,11 +53,14 @@
 #define PANKEYFUNZC \
 	ZC_panPageManual(&mv, &player, 0);
 
-#define FUNCTIONKEYDRAWJUNK \
+#define FUNCTIONKEYSHOWMV \
 	if(IN_KeyDown(1+1)){ gvar.video.sp=0; ZC_ShowMV(&mv, 0, 0); } \
 	if(IN_KeyDown(2+1)){ gvar.video.sp=1; ZC_ShowMV(&mv, 0, 0); } \
 	if(IN_KeyDown(3+1)){ gvar.video.sp=2; ZC_ShowMV(&mv, 0, 1); } \
 	if(IN_KeyDown(4+1)){ gvar.video.sp=3; ZC_ShowMV(&mv, 0, 1); } \
+
+#define FUNCTIONKEYDRAWJUNK \
+	FUNCTIONKEYSHOWMV \
 	FUNCTIONKEYDRAWJUNKNOMV
 
 #define FUNCTIONKEYDRAWJUNKNOMV \
diff --git a/src/lib/16_tdef.h b/src/lib/16_tdef.h
index 206598c4..0a4248ba 100755
--- a/src/lib/16_tdef.h
+++ b/src/lib/16_tdef.h
@@ -249,6 +249,11 @@ typedef struct
 } kurokku_t;
 
 //video
+typedef struct
+{
+	unsigned int offscreen_ofs;
+	unsigned int pattern_ofs;
+} ofs_t;
 #define NUMCHUNKS	416	//keen
 
 typedef struct
@@ -271,6 +276,7 @@ typedef struct
 	word pr[MAXPAGE][4];	//render sections of pages (this is supposed to be set up to draw sections of the screen if updated)
 
 	nibble sfip;		//shinku_fps_indicator_page; // we're on page 1 now, shinku(). follow along please or it will not be visible.
+	ofs_t	ofs;		//offset vars used for doslib
 	word	vh;		//video combined height
 	//0000word startclk; float clk, tickclk;	//timer
 //newer vars
diff --git a/src/lib/16_vl.c b/src/lib/16_vl.c
index 31a76ce6..083e2124 100755
--- a/src/lib/16_vl.c
+++ b/src/lib/16_vl.c
@@ -277,6 +277,12 @@ void modexCalcVmemRemain(video_t *video)
 	}
 }
 
+void VL_Initofs(video_t *video)
+{
+	video->ofs.offscreen_ofs =	video->page[0].pagesize+video->page[1].pagesize;//(vga_state.vga_stride * vga_state.vga_height);
+	video->ofs.pattern_ofs =	(uint16_t)video->page[2].data;
+}
+
 void modexHiganbanaPageSetup(video_t *video)
 {
 	video->vmem_remain=65535U;
@@ -290,9 +296,12 @@ void modexHiganbanaPageSetup(video_t *video)
  	(video->page[2]) = modexNextPageFlexibleSize(&(video->page[1]), video->page[0].width, 96);	video->num_of_pages++;
  	(video->page[3]) = modexNextPageFlexibleSize(&(video->page[2]), video->page[0].width, 96);	video->num_of_pages++;
 	modexCalcVmemRemain(video);
+
 	video->sp=video->p=0;
 	video->r=1;
 	video->vh=video->page[0].height+video->page[1].height+video->page[3].height-8;//+video->page[2].height
+
+	VL_Initofs(video);
 	//doslib origi var
 	video->omemptr=			vga_state.vga_graphics_ram;
 	video->vga_draw_stride=	vga_state.vga_draw_stride;
diff --git a/src/lib/16_vl.h b/src/lib/16_vl.h
index 97438aff..3ce8d71a 100755
--- a/src/lib/16_vl.h
+++ b/src/lib/16_vl.h
@@ -102,6 +102,7 @@ page_t modexDefaultPage(page_t *p);
 page_t modexNextPage(page_t *p);
 page_t modexNextPageFlexibleSize(page_t *p, word x, word y);
 void modexCalcVmemRemain(video_t *video);
+void VL_Initofs(video_t *video);
 void modexHiganbanaPageSetup(video_t *video);
 //void modexShowPage(page_t *page);
 void VL_ShowPage(page_t *page, boolean vsync, boolean sr);
diff --git a/src/lib/scroll16.c b/src/lib/scroll16.c
index 4ad596f0..dd37e3fe 100755
--- a/src/lib/scroll16.c
+++ b/src/lib/scroll16.c
@@ -348,12 +348,12 @@ allocMap(int w, int h) {
 	return result;
 }*/
 
-/*void
+void
 initMap(map_t *map) {
 	// just a place holder to fill out an alternating pattern
-	int x, y, xx, yy;
-	int i, q;
-//	int tile = 1;
+	int x, y;//, xx, yy;
+	int i;//, q;
+	int tile = 1;
 	//if(!isEMS() || !checkEMS())
 //		map->tiles = malloc(sizeof(tiles_t));
 	//else
@@ -375,7 +375,7 @@ initMap(map_t *map) {
 //	map->tiles->rows = 1;
 //	map->tiles->cols = 1;//2;
 
-	q=0;
+/*	q=0;
 	//for(y=0; y<map->height; y++) {
 	//for(x=0; x<map->width; x++) {
 	i=0;
@@ -393,7 +393,7 @@ initMap(map_t *map) {
 //	printf("\n");
 	}
 //	printf("[%d]", map->data[q]);
-	q++;
+	q++;*/
 //	}
 	//printf("\n\n");
 //	}
@@ -401,14 +401,14 @@ initMap(map_t *map) {
 	i=0;
 	for(y=0; y<map->height; y++) {
 		for(x=0; x<map->width; x++) {
-//			map->data[i]=255;
-			printf("[%d]", map->data[i]);
-			//tile = tile ? 0 : 1;
+			map->data[i]=255;
+//			printf("[%d]", map->data[i]);
+			tile = tile ? 0 : 1;
 			i++;
 		}
-		//tile = tile ? 0 : 1;
+		tile = tile ? 0 : 1;
 	}
-}*/
+}
 
 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
 {
diff --git a/src/lib/scroll16.h b/src/lib/scroll16.h
index dc81f873..c3260f78 100755
--- a/src/lib/scroll16.h
+++ b/src/lib/scroll16.h
@@ -95,7 +95,7 @@ extern boolean pagenorendermap, pagedelayrendermap;
 extern char global_temp_status_text[512];
 
 //map_t allocMap(int w, int h);
-//void initMap(map_t *map);
+void initMap(map_t *map);
 void ZC_walk(map_view_t *pip, player_t *player, word pn);
 //void oldwalk(map_view_t *pip, player_t *player, word pn);
 void ZC_panPageManual(map_view_t *pip, player_t *player, word pn);
diff --git a/src/scroll.c b/src/scroll.c
index be6f43d1..98e5a160 100755
--- a/src/scroll.c
+++ b/src/scroll.c
@@ -119,7 +119,7 @@ void main(int argc, char *argv[])
 	mapGoTo(&mv, 0, 0);
 
 	playerXYpos(0, 0, &player, &mv, 0);
-	EN_initplayer(&player, 0);
+	EN_initplayer(&player, 0, &gvar.video);
 	player[0].enti.spri->x = player[0].enti.x-4;
 	player[0].enti.spri->y = player[0].enti.y-16;
 
diff --git a/src/test.c b/src/test.c
index 190b396b..839915fc 100755
--- a/src/test.c
+++ b/src/test.c
@@ -83,7 +83,7 @@ void main(int argc, char *argv[])
 
 	//IN_Startup();
 	IN_Default(0,&player,ctrl_Keyboard1);
-	EN_initplayer(&player, 0);
+	EN_initplayer(&player, 0, &gvar.video);
 
 	VGAmodeX(1, 1, &gvar);
 	//====modexPalBlack();
diff --git a/src/zcroll.c b/src/zcroll.c
index 1e783794..6cdba594 100755
--- a/src/zcroll.c
+++ b/src/zcroll.c
@@ -84,6 +84,7 @@ void main(int argc, char *argv[])
 //	fprintf(stderr, "testing map load~	");
 	loadmap("data/test.map", &map);
 	chkmap(&map, 0);
+//	initMap(&map);
 //	printf("chkmap ok	");
 //	fprintf(stderr, "yay map loaded~~\n");
 
@@ -131,7 +132,7 @@ void main(int argc, char *argv[])
 	mapGoTo(&mv, 0, 0);
 
 	playerXYpos(0, 0, &player, &mv, 0);
-	EN_initplayer(&player, 0);
+	EN_initplayer(&player, 0, &gvar.video);
 	player[0].enti.spri->x = player[0].enti.x-4;
 	player[0].enti.spri->y = player[0].enti.y-16;
 
@@ -148,9 +149,10 @@ void main(int argc, char *argv[])
 		modexFadeOn(4, dpal);
 #endif
 	}
-	animate_spri(&(player[0].enti), &gvar.video);
 
+//	while(!IN_KeyDown(sc_Escape) && !IN_KeyDown(sc_Space) && !IN_KeyDown(sc_Enter)){ FUNCTIONKEYSHOWMV }
 	VL_ShowPage(mv[0].page, 0, 0);//modexShowPage(mv[0].page);//!(gvar.video.p)
+	animate_spri(&(player[0].enti), &gvar.video);
 #ifdef FADE
 	modexFadeOn(4, gpal);
 #endif
-- 
2.39.5