]> 4ch.mooo.com Git - 16.git/blob - src/lib/scroll16.c
p16 is being worked on a bunch by me wwww [16_ca needs huge amounts of work and I...
[16.git] / src / lib / scroll16.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 /*\r
23         scroll16 library~\r
24 */\r
25 #include "src/lib/scroll16.h"\r
26 \r
27 //#define INC_PER_FRAME if(player[pn].enti.q&1) player[pn].enti.persist_aniframe++; if(player[pn].enti.persist_aniframe>4) player[pn].enti.persist_aniframe = 1;\r
28 \r
29 void ZC_walk(map_view_t *pip, player_t *player, word pn)\r
30 {\r
31         switch(player[pn].enti.d)\r
32         {\r
33                 //no direction\r
34                 case 2:\r
35                         //0000pip[0].video->startclk = (*clockw);\r
36                 break;\r
37                 //right movement\r
38                 case 3:\r
39                         if(ZC_mapEdgeChk(pip, player[pn].enti.d, 0) && player[pn].enti.tx == pip[0].tx+pip[0].page->ti.tilemidposscreenx &&\r
40                         !(pip[0].map->layerdata[0].data[(player[pn].enti.tx)+(pip[0].map->width*(player[pn].enti.ty-1))] == 0))//!(player[pn].enti.tx+1 == TRIGGX && player[pn].enti.ty == TRIGGY))     //collision detection!\r
41                         {\r
42                                 player[pn].walktype=2;\r
43                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
44                                 {\r
45                                         ZC_animatePlayer(pip, player, pn);\r
46                                         ZC_mapScroll(pip, player, pn);\r
47                                         player[pn].enti.q++;\r
48                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;\r
49                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx++; }\r
50                         }\r
51                         else if(player[pn].enti.tx < pip[0].map->width && !(pip[0].map->layerdata[0].data[(player[pn].enti.tx)+(pip[0].map->width*(player[pn].enti.ty-1))] == 0))//!(player[pn].enti.tx+1 == TRIGGX && player[pn].enti.ty == TRIGGY))\r
52                         {\r
53                                 player[pn].walktype=1;\r
54                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
55                                 {\r
56                                         player[pn].enti.x+=(player[pn].enti.speed);\r
57                                         ZC_animatePlayer(pip, player, pn);\r
58                                         player[pn].enti.q++;\r
59                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx++; }\r
60                         }\r
61                         else\r
62                         {\r
63                                 player[pn].walktype=0;\r
64                                 ZC_animatePlayer(pip, player, pn);\r
65                                 player[pn].enti.d = 2;\r
66                         }\r
67                         player[pn].enti.triggerx = player[pn].enti.tx+1;\r
68                         player[pn].enti.triggery = player[pn].enti.ty;\r
69                 break;\r
70                 //left movement\r
71                 case 1:\r
72                         if(ZC_mapEdgeChk(pip, player[pn].enti.d, 0) && player[pn].enti.tx == pip[0].tx+pip[0].page->ti.tilemidposscreenx &&\r
73                         !(pip[0].map->layerdata[0].data[(player[pn].enti.tx-2)+(pip[0].map->width*(player[pn].enti.ty-1))] == 0))//!(player[pn].enti.tx-1 == TRIGGX && player[pn].enti.ty == TRIGGY))   //collision detection!\r
74                         {\r
75                                 player[pn].walktype=2;\r
76                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
77                                 {\r
78                                         ZC_animatePlayer(pip, player, pn);\r
79                                         ZC_mapScroll(pip, player, pn);\r
80                                         player[pn].enti.q++;\r
81                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;\r
82                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx--; }\r
83                         }\r
84                         else if(player[pn].enti.tx > 1 && !(pip[0].map->layerdata[0].data[(player[pn].enti.tx-2)+(pip[0].map->width*(player[pn].enti.ty-1))] == 0))//!(player[pn].enti.tx-1 == TRIGGX && player[pn].enti.ty == TRIGGY))\r
85                         {\r
86                                 player[pn].walktype=1;\r
87                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
88                                 {\r
89                                         player[pn].enti.x-=(player[pn].enti.speed);\r
90                                         ZC_animatePlayer(pip, player, pn);\r
91                                         player[pn].enti.q++;\r
92                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.tx--; }\r
93                         }\r
94                         else\r
95                         {\r
96                                 player[pn].walktype=0;\r
97                                 ZC_animatePlayer(pip, player, pn);\r
98                                 player[pn].enti.d = 2;\r
99                         }\r
100                         player[pn].enti.triggerx = player[pn].enti.tx-1;\r
101                         player[pn].enti.triggery = player[pn].enti.ty;\r
102                 break;\r
103                 //down movement\r
104                 case 4:\r
105                         if(ZC_mapEdgeChk(pip, player[pn].enti.d, 0) && player[pn].enti.ty == pip[0].ty+pip[0].page->ti.tilemidposscreeny &&\r
106                         !(pip[0].map->layerdata[0].data[(player[pn].enti.tx-1)+(pip[0].map->width*(player[pn].enti.ty))] == 0))//!(player[pn].enti.tx == TRIGGX && player[pn].enti.ty+1 == TRIGGY))     //collision detection!\r
107                         {\r
108                                 player[pn].walktype=2;\r
109                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
110                                 {\r
111                                         ZC_animatePlayer(pip, player, pn);\r
112                                         ZC_mapScroll(pip, player, pn);\r
113                                         player[pn].enti.q++;\r
114                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;\r
115                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty++; }\r
116                         }\r
117                         else if(player[pn].enti.ty < pip[0].map->height && !(pip[0].map->layerdata[0].data[(player[pn].enti.tx-1)+(pip[0].map->width*(player[pn].enti.ty))] == 0))//!(player[pn].enti.tx == TRIGGX && player[pn].enti.ty+1 == TRIGGY))\r
118                         {\r
119                                 player[pn].walktype=1;\r
120                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
121                                 {\r
122                                         player[pn].enti.y+=(player[pn].enti.speed);\r
123                                         ZC_animatePlayer(pip, player, pn);\r
124                                         player[pn].enti.q++;\r
125                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty++; }\r
126                         }\r
127                         else\r
128                         {\r
129                                 player[pn].walktype=0;\r
130                                 ZC_animatePlayer(pip, player, pn);\r
131                                 player[pn].enti.d = 2;\r
132                         }\r
133                         player[pn].enti.triggerx = player[pn].enti.tx;\r
134                         player[pn].enti.triggery = player[pn].enti.ty+1;\r
135                 break;\r
136                 //up movement\r
137                 case 0:\r
138                         if(ZC_mapEdgeChk(pip, player[pn].enti.d, 0) && player[pn].enti.ty == pip[0].ty+pip[0].page->ti.tilemidposscreeny &&\r
139                         !(pip[0].map->layerdata[0].data[(player[pn].enti.tx-1)+(pip[0].map->width*(player[pn].enti.ty-2))] == 0))//!(player[pn].enti.tx == TRIGGX && player[pn].enti.ty-1 == TRIGGY))   //collision detection!\r
140                         {\r
141                                 player[pn].walktype=2;\r
142                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
143                                 {\r
144                                         ZC_animatePlayer(pip, player, pn);\r
145                                         ZC_mapScroll(pip, player, pn);\r
146                                         player[pn].enti.q++;\r
147                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;\r
148                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty--; }\r
149                         }\r
150                         else if(player[pn].enti.ty > 1 && !(pip[0].map->layerdata[0].data[(player[pn].enti.tx-1)+(pip[0].map->width*(player[pn].enti.ty-2))] == 0))//!(player[pn].enti.tx == TRIGGX &&  player[pn].enti.ty-1 == TRIGGY))\r
151                         {\r
152                                 player[pn].walktype=1;\r
153                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
154                                 {\r
155                                         player[pn].enti.y-=(player[pn].enti.speed);\r
156                                         ZC_animatePlayer(pip, player, pn);\r
157                                         player[pn].enti.q++;\r
158                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; player[pn].enti.ty--; }\r
159                         }\r
160                         else\r
161                         {\r
162                                 player[pn].walktype=0;\r
163                                 ZC_animatePlayer(pip, player, pn);\r
164                                 player[pn].enti.d = 2;\r
165                         }\r
166                         player[pn].enti.triggerx = player[pn].enti.tx;\r
167                         player[pn].enti.triggery = player[pn].enti.ty-1;\r
168                 break;\r
169         }\r
170 }\r
171 \r
172 \r
173 //panning page\r
174 void ZC_panPageManual(map_view_t *pip, player_t *player, word pn)\r
175 {\r
176 #define SHOWMVFUN_ ZC_ShowMV(pip, 0, 0);\r
177         switch(player[pn].enti.d)\r
178         {\r
179                 //right movement\r
180                 case 3:\r
181                         if(ZC_mapEdgeChk(pip, player[pn].enti.d, 1))\r
182                         {\r
183                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
184                                 {\r
185                                         pip[0].page->dx+=4;\r
186                                         SHOWMVFUN_;\r
187                                         player[pn].enti.q++;\r
188                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].tx++; }\r
189                         }\r
190                 break;\r
191 \r
192                 //left movement\r
193                 case 1:\r
194                         if(ZC_mapEdgeChk(pip, player[pn].enti.d, 1))\r
195                         {\r
196                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
197                                 {\r
198                                         pip[0].page->dx-=4;\r
199                                         SHOWMVFUN_;\r
200                                         player[pn].enti.q++;\r
201                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].tx--; }\r
202                         }\r
203                 break;\r
204 \r
205                 //down movement\r
206                 case 4:\r
207                         if(ZC_mapEdgeChk(pip, player[pn].enti.d, 1))\r
208                         {\r
209                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
210                                 {\r
211                                         pip[0].page->dy+=4;\r
212                                         SHOWMVFUN_;\r
213                                         player[pn].enti.q++;\r
214                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].ty++; }\r
215                         }\r
216                 break;\r
217 \r
218                 //up movement\r
219                 case 0:\r
220                         if(ZC_mapEdgeChk(pip, player[pn].enti.d, 1))\r
221                         {\r
222                                 if(player[pn].enti.q<=player[pn].enti.spt)\r
223                                 {\r
224                                         pip[0].page->dy-=4;\r
225                                         SHOWMVFUN_;\r
226                                         player[pn].enti.q++;\r
227                                 } else { player[pn].enti.q = 1; player[pn].enti.d = 2; pip[0].ty--; }\r
228                         }\r
229                 break;\r
230         }\r
231 }\r
232 \r
233 /*\r
234  * modex mv setup\r
235 */\r
236 void ZC_MVSetup(map_view_t *pip, map_t *map, global_game_variables_t *gv)\r
237 {\r
238 #define ZC_MVI 1\r
239         nibble i;\r
240         // 1st page\r
241         pip[0].page = &gv->video.page[0];\r
242         pip[0].map = map;\r
243         pip[0].video = &gv->video;\r
244         pip[0].p        = &gv->video.p;\r
245         pip[0].sp       = &gv->video.sp;\r
246         ZC_MVInit(pip, 1, 1);\r
247 \r
248         for(i=ZC_MVI;i<gv->video.num_of_pages;i++)\r
249         {\r
250                 pip[i].page     =       &gv->video.page[i];\r
251                 pip[i].map      =       pip[0].map;\r
252                 pip[i].video    =       pip[0].video;\r
253                 pip[i].p        =       pip[0].p;\r
254                 pip[i].sp       =       pip[0].sp;\r
255 //              if(i>ZC_MVI) {\r
256                 pip[i].tx =     1;\r
257                 pip[i].ty =     1;\r
258 //              }\r
259         }\r
260 }\r
261 \r
262 void ZC_MVInit(map_view_t *pip, int tx, int ty)\r
263 {\r
264         pip[0].tx = tx;\r
265         pip[0].ty = ty;\r
266         //pip[0].tx = pip[1].tx = tx;\r
267         //pip[0].ty = pip[1].ty = ty;\r
268 }\r
269 \r
270 void ZC_ShowMV(map_view_t *moo, boolean vsync, boolean sr)\r
271 {\r
272         word high_address, low_address, offset;\r
273         byte crtcOffset;\r
274 \r
275         // calculate offset\r
276         offset = (word) moo[moo[0].video->sp].page->data;\r
277         offset += moo[0].page->dy * (moo[0].page->width >> 2 );\r
278         offset += moo[0].page->dx >> 2;\r
279 \r
280         // calculate crtcOffset according to virtual width\r
281         switch(sr)\r
282         {\r
283                 case 1:\r
284                         crtcOffset = moo[moo[0].video->sp].page->sw >> 3;\r
285                 break;\r
286                 default:\r
287                 case 0:\r
288                         crtcOffset = moo[0].page->width >> 3;\r
289                 break;\r
290         }\r
291 \r
292         high_address = HIGH_ADDRESS | (offset & 0xff00);\r
293         low_address  = LOW_ADDRESS  | (offset << 8);\r
294 \r
295         // wait for appropriate timing and then program CRTC\r
296         if(vsync) while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE));\r
297         outpw(CRTC_INDEX, high_address);\r
298         outpw(CRTC_INDEX, low_address);\r
299         outp(CRTC_INDEX, 0x13);\r
300         outp(CRTC_DATA, crtcOffset);\r
301 \r
302         // wait for one retrace\r
303         if(vsync) while (!(inp(INPUT_STATUS_1) & VRETRACE));\r
304 \r
305         // do PEL panning here\r
306         outp(AC_INDEX, 0x33);\r
307         outp(AC_INDEX, (moo[0].page->dx & 0x03) << 1);\r
308         vga_state.vga_draw_stride_limit = vga_state.vga_draw_stride = moo[0].page->stridew;\r
309 }\r
310 \r
311 #if 0\r
312 void\r
313 initMap(map_t *map) {\r
314         // just a place holder to fill out an alternating pattern\r
315         int x, y;\r
316         int i;\r
317         int tile = 1;\r
318 \r
319         i=0;\r
320         for(y=0; y<map->height; y++) {\r
321                 for(x=0; x<map->width; x++) {\r
322                         map->layerdata[0].data[i]=255;\r
323 //                      printf("[%d]", map->layerdata[0].data[i]);\r
324                         tile = tile ? 0 : 1;\r
325                         i++;\r
326                 }\r
327                 tile = tile ? 0 : 1;\r
328         }\r
329 }\r
330 \r
331 void\r
332 initMap(map_t *map) {\r
333         /* just a place holder to fill out an alternating pattern */\r
334         int x, y;\r
335         int i;\r
336         int tile = 1;\r
337         map->tiles = malloc(sizeof(tiles_t));\r
338         map->width=20;\r
339         map->height=15;\r
340 \r
341         /* create the tile set */\r
342         map->tiles->spri = malloc(sizeof(sprite_t));\r
343         map->tiles->spri->sprite_vrl_cont.vrl_header->width = (TILEWH*2);\r
344         map->tiles->spri->sprite_vrl_cont.vrl_header->height= TILEWH;\r
345         map->tiles->spri->sprite_vrl_cont.buffer = malloc((TILEWH*2)*TILEWH);\r
346         map->tiles->tileHeight = TILEWH;\r
347         map->tiles->tileWidth =TILEWH*2;\r
348         map->tiles->rows = 1;\r
349         map->tiles->cols = 2;\r
350 //#if 0\r
351         i=0;\r
352         for(y=0; y<TILEWH; y++) {\r
353         for(x=0; x<(TILEWH*2); x++) {\r
354                 if(x<TILEWH)\r
355                         map->tiles->spri->sprite_vrl_cont.buffer[i] = 28;//0x24;\r
356                 else\r
357                         map->tiles->spri->sprite_vrl_cont.buffer[i] = 0;//0x34;\r
358                 i++;\r
359         }\r
360         }\r
361 //#endif\r
362         i=0;\r
363         printf("pee\n");\r
364         for(y=0; y<map->height; y++) {\r
365                 for(x=0; x<map->width; x++) {\r
366                         map->layerdata[0].data[i] = tile;\r
367 //                      printf("%u ", map->layerdata[0].data[i]);\r
368                         tile = tile ? 0 : 1;\r
369                         i++;\r
370                 }\r
371 //              printf("\n");\r
372                 tile = tile ? 0 : 1;\r
373         }\r
374 }\r
375 #endif\r
376 //===========================================================================//\r
377 \r
378 \r
379 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)\r
380 {\r
381         word x;//, y;  /* coordinate for drawing */\r
382 \r
383         ScrollRight(mv, player, id, plid);\r
384 \r
385         /* draw the next column */\r
386         x= mv[0].page->sw + mv[0].map->tiles->tileWidth;\r
387         if(ZC_mapEdgeChk(mv, player[plid].enti.d, 0))\r
388 #ifndef FULLRCREND\r
389         if(player[plid].enti.q%4)\r
390 #else\r
391         if(player[plid].enti.q==4)\r
392 #endif\r
393 //              if(id==0)\r
394                         mapDrawCol(&mv[id], mv[0].tx + mv[0].page->ti.tw, mv[0].ty-1, x, player, DRAWCOLNUM);\r
395 //              else\r
396 //                      if(mv[0].video->vga_state.bgps)\r
397 //                              modexCopyPageRegion(mv->page, mv[0].page, x, 0, x, 0, mv[0].map->tiles->tileWidth, mv[0].page->height);\r
398         //mv[0].video->dorender=1;//ScrollRight\r
399 }\r
400 \r
401 \r
402 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)\r
403 {\r
404         word x;//,y;  /* coordinate for drawing */\r
405 \r
406         ScrollLeft(mv, player, id, plid);\r
407 \r
408         /* draw the next column */\r
409         x= 0;\r
410         if(ZC_mapEdgeChk(mv, player[plid].enti.d, 0))\r
411 #ifndef FULLRCREND\r
412         if(player[plid].enti.q%4)\r
413 #else\r
414         if(player[plid].enti.q==4)\r
415 #endif\r
416 //              if(id==0)\r
417                         mapDrawCol(&mv[id], mv[0].tx - 1, mv[0].ty-1, x, player, DRAWCOLNUM);\r
418 //              else\r
419 //                      if(mv[0].video->vga_state.bgps)\r
420 //                              modexCopyPageRegion(mv->page, mv[0].page, x, 0, x, 0, mv[0].map->tiles->tileWidth, mv[0].page->height);\r
421         //mv[0].video->dorender=1;//ScrollLeft\r
422 }\r
423 \r
424 \r
425 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)\r
426 {\r
427         word y;//x,  /* coordinate for drawing */\r
428 \r
429         ScrollUp(mv, player, id, plid);\r
430 \r
431         /* draw the next row */\r
432         y= 0;\r
433         if(ZC_mapEdgeChk(mv, player[plid].enti.d, 0))\r
434 #ifndef FULLRCREND\r
435         if(player[plid].enti.q%3)\r
436 #else\r
437         if(player[plid].enti.q==4)\r
438 #endif\r
439 //              if(id==0)\r
440                         mapDrawRow(&mv[id], mv[0].tx - 1, mv[0].ty-1, y, player, DRAWROWNUM);\r
441 //              else\r
442 //                      if(mv[0].video->vga_state.bgps)\r
443 //                              modexCopyPageRegion(mv->page, mv[0].page, 0, y, 0, y, mv[0].page->width, mv[0].map->tiles->tileHeight);\r
444         //mv[0].video->dorender=1;//ScrollUp\r
445 }\r
446 \r
447 \r
448 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)\r
449 {\r
450         word y;//x,  /* coordinate for drawing */\r
451 \r
452         ScrollDown(mv, player, id, plid);\r
453 \r
454         /* draw the next row */\r
455         y= mv[0].page->sh + mv[0].map->tiles->tileHeight;\r
456         if(ZC_mapEdgeChk(mv, player[plid].enti.d, 0))\r
457 #ifndef FULLRCREND\r
458         if(player[plid].enti.q%3)\r
459 #else\r
460         if(player[plid].enti.q==4)\r
461 #endif\r
462 //              if(id==0)\r
463                         mapDrawRow(&mv[id], mv[0].tx - 1, mv[0].ty+mv[0].page->ti.th, y, player, DRAWROWNUM);\r
464 //              else\r
465 //                      if(mv[0].video->vga_state.bgps)\r
466 //                              modexCopyPageRegion(mv->page, mv[0].page, 0, y, 0, y, mv[0].page->width, mv[0].map->tiles->tileHeight);\r
467         //mv[0].video->dorender=1;//ScrollDown\r
468 }\r
469 \r
470 void ZC_mapScroll(map_view_t *mv, player_t *player, word pn)\r
471 {\r
472         word b = mv[0].video->vga_state.bgps;\r
473         switch(player[pn].enti.d)\r
474         {\r
475                 case 2://none\r
476                 break;\r
477                 case 3://right\r
478                                 ScrollRight(mv, player, 3, pn);\r
479                                 ScrollRight(mv, player, 2, pn);\r
480                                 mapScrollRight(mv, player, (0), pn);\r
481                         if(b)   mapScrollRight(mv, player, (1), pn);\r
482                 break;\r
483                 case 1://left\r
484                                 ScrollLeft(mv, player, 3, pn);\r
485                                 ScrollLeft(mv, player, 2, pn);\r
486                                 mapScrollLeft(mv, player, (0), pn);\r
487                         if(b)   mapScrollLeft(mv, player, (1), pn);\r
488                 break;\r
489                 case 4://down\r
490                                 ScrollDown(mv, player, 3, pn);\r
491                                 ScrollDown(mv, player, 2, pn);\r
492                                 mapScrollDown(mv, player, (0), pn);\r
493                         if(b)   mapScrollDown(mv, player, (1), pn);\r
494                 break;\r
495                 case 0://up\r
496                                 ScrollUp(mv, player, 3, pn);\r
497                                 ScrollUp(mv, player, 2, pn);\r
498                                 mapScrollUp(mv, player, (0), pn);\r
499                         if(b)   mapScrollUp(mv, player, (1), pn);\r
500                 break;\r
501         }\r
502         //mv[0].video->dorender=1;//ZC_mapScroll\r
503 }\r
504 \r
505 //===========================================================================\r
506 //TODO: put player in starting position of assigned spot on map\r
507 //default player position on the viewable map\r
508 void ZC_PlayerXYpos(int x, int y, player_t *player, map_view_t *pip, nibble pn, boolean defaultsw)\r
509 {\r
510         player[pn].enti.tx = x + pip[0].tx;\r
511         player[pn].enti.ty = y + pip[0].ty;\r
512 \r
513         switch(defaultsw)\r
514         {\r
515                 case 1:\r
516                         player[pn].enti.tx += pip[0].page->ti.tilemidposscreenx;\r
517                         player[pn].enti.ty += pip[0].page->ti.tilemidposscreeny;\r
518                 break;\r
519                 case 0:\r
520                 break;\r
521         }\r
522 }\r
523 //===========================================================================\r
524 \r
525 void ZC_checkardmap(map_t *map)\r
526 {\r
527         // just a place holder to fill out an alternating pattern\r
528         int x, y;\r
529         int i;\r
530         static byte z[(MAPW*MAPH)];//map->width*map->height];\r
531         byte tile = 1;\r
532 \r
533         i=0;\r
534         for(y=0; y<map->height; y++) {\r
535                 for(x=0; x<map->width; x++) {\r
536                         z[i]=tile+1;\r
537                         tile = tile ? 0 : 1;\r
538                         i++;\r
539                 }\r
540                 tile = tile ? 0 : 1;\r
541         }\r
542         map->layerdata[0].data = &z;\r
543 }\r
544 \r
545 sword chkmap(map_t *map, word q)\r
546 {\r
547 //      bitmap_t bp;\r
548 //      static byte x[(MAPW*MAPH)+1] =\r
549 //{ 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, 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1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1 };\r
551 //1,    2,      3,      4,      0,      3,      3,      3,      3,      3,      3,      3,      3,      4,      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,      9,      10,     11,     12,     4,      1,      0,      1,      0,      0,      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,      0,      0,      4,      0,      0,      0,      0,      0,      8,      8,      1,      11,     11,     3,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      0,      0,      0,      0,      8,      8,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      3,      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,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      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,      3,      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,      3,      3,      3,      3,      1,      2,      3,      4 };\r
552         //check for failed to load map\r
553         if((map->width == map->height == 0) && (q>0))\r
554         {\r
555                 //initiate a null map!\r
556                 map->width=MAPW;\r
557                 map->height=MAPH;\r
558 //              map->layerdata[0].data = fmfaflflfofcf(((map->width*map->height)+1)*sizeof(byte));\r
559                 ZC_checkardmap(map);//map->layerdata[0].data = &x;\r
560                 //fix this to be far~\r
561 //              bp = bitmapLoadPcx("data/ed.pcx");\r
562 //              map->tiles->data = &bp;\r
563                 map->tiles->tileHeight = 16;\r
564                 map->tiles->tileWidth = 16;\r
565                 map->tiles->rows = 1;\r
566                 map->tiles->cols = 1;\r
567         }\r
568         return 0;\r
569 }\r
570 \r
571 //TODO: player position here\r
572 void mapGoTo(map_view_t *mv, int tx, int ty)\r
573 {\r
574         ZC_mapinitMV(mv, tx, ty);\r
575 \r
576         /* draw the tiles */\r
577         modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 0);\r
578         ZC_mapredraw(mv, tx, ty);\r
579 \r
580         //if(mv[0].video->vga_state.bgps) modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);\r
581 }\r
582 \r
583 void ZC_mapinitMV(map_view_t *mv, int tx, int ty)\r
584 {\r
585         /* set up the coordinates */\r
586         mv[0].tx = mv[1].tx = tx;\r
587         mv[0].ty = mv[1].ty = ty;\r
588         mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->tiles->tileWidth;\r
589         mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->tiles->tileHeight;\r
590 \r
591         /* set up the thresholds */\r
592         mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileWidth * 2;\r
593         mv[0].dyThresh = mv[1].dyThresh = mv[2].dyThresh = mv[3].dyThresh = mv->map->tiles->tileHeight * 2;\r
594 }\r
595 \r
596 void ZC_mapredraw(map_view_t *mv, int tx, int ty)\r
597 {\r
598         int py;//px,\r
599         unsigned int i;\r
600 \r
601         py=0;\r
602         i=mv[0].ty * mv[0].map->width + mv[0].tx;\r
603         for(ty=mv[0].ty-1; py < mv[0].page->sh+mv->dyThresh && ty < mv[0].map->height; ty++, py+=mv[0].map->tiles->tileHeight) {\r
604                 mapDrawWRow(&mv[0], tx-1, ty, py);\r
605                 mapDrawWRow(&mv[1], tx-1, ty, py);\r
606                 i+=mv->map->width - tx;\r
607         }\r
608 }\r
609 \r
610 void near\r
611 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)\r
612 {\r
613         word rx, ry;\r
614 //      printf("%02d ", i); if(x >= page->width - t->tileWidth) printf("\n");\r
615         switch(i)\r
616         {\r
617                 case 0:\r
618                         //wwww\r
619                         modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 1); //currently the over scan color!\r
620                 break;\r
621                 default:\r
622                         rx = (((i-1) % ((t->spri->sprite_vrl_cont.vrl_header->width)/t->tileWidth)) * t->tileWidth);\r
623                         ry = (((i-1) / ((t->spri->sprite_vrl_cont.vrl_header->height)/t->tileHeight)) * t->tileHeight);\r
624 #ifndef TILERENDER\r
625 #ifdef __DEBUG_RF__\r
626                         if(!dbg_pagenorendermap)\r
627 #endif\r
628                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, i+1);\r
629 #else\r
630                         modexDrawBmpRegion              (page, x, y, rx, ry, t->tileWidth, t->tileHeight, i);\r
631                         //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));\r
632                         //modexDrawBmpRegion    (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));\r
633 #endif\r
634 #ifdef __DEBUG_MAP__\r
635                         if(dbg_maptext){ sprintf(global_temp_status_text2, "%u", i); modexprint(page, x, y, 1, 0, 1, 2, 1, global_temp_status_text2); }\r
636 #endif\r
637                 break;\r
638         }\r
639 }\r
640 #define PALMAPDRAWW 13\r
641 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *player, word poopoffset)\r
642 {\r
643         int i; nibble z;\r
644 #ifdef __DEBUG_RF__\r
645 if(dbg_pagedelayrendermap)              if(!y)  y+=TILEWH;      else    y-=TILEWH;\r
646 #endif\r
647         poopoffset%=player[0].enti.speed;\r
648 //printf("y: %d\n", poopoffset);\r
649 #ifdef __DEBUG_RF__\r
650 if(dbg_pagedelayrendermap){ sprintf(global_temp_status_text, "%-3u", mv->dx); modexprint(mv[0].page, player[0].enti.x, player[0].enti.y-28-(poopoffset*8) , 1, 0, PALMAPDRAWW, 1, 1, global_temp_status_text); }\r
651 #endif\r
652         /* the position within the map array */\r
653         i=ty * mv->map->width + tx;\r
654         for(    mv->dx=poopoffset;      mv->dx<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width;       mv->dx+=mv->map->tiles->tileWidth, tx++) {\r
655                 if(i>=0){\r
656                         mapDrawTile(mv->map->tiles, mv->map->layerdata[0].data[i], mv->page, mv->dx, y);\r
657                         for(z=1;z<=2;z++)\r
658                                 if(mv->map->layerdata[z].data[i]){\r
659                                         sprintf(global_temp_status_text2, "%u", mv->map->layerdata[z].data[i]); modexprint(mv->page, mv->dx, y, 1, 0, PALMAPDRAWW, z+2, 1, global_temp_status_text2);\r
660                                         //mapDrawTile(mv->map->tiles, mv->map->layerdata[z].data[i], mv->page, mv->dx, y);\r
661                                 }\r
662                 }\r
663                 i++; /* next! */\r
664         }\r
665 #ifdef __DEBUG_RF__\r
666 if(dbg_pagedelayrendermap) delay(200);\r
667 #endif\r
668 }\r
669 \r
670 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *player, word poopoffset)\r
671 {\r
672         int i; nibble z;\r
673 #ifdef __DEBUG_RF__\r
674 if(dbg_pagedelayrendermap)              if(!x)  x+=TILEWH;              else    x-=TILEWH;\r
675 #endif\r
676         poopoffset%=player[0].enti.speed;\r
677 //printf("x: %d\n", poopoffset);\r
678 #ifdef __DEBUG_RF__\r
679 if(dbg_pagedelayrendermap){ sprintf(global_temp_status_text, "%-3u", mv->dy); modexprint(mv[0].page, player[0].enti.x, player[0].enti.y-28-(poopoffset*8) , 1, 0, PALMAPDRAWW, 1, global_temp_status_text); }\r
680 #endif\r
681         /* location in the map array */\r
682         i=ty * mv->map->width + tx;\r
683         /* We'll copy all of the columns in the screen,\r
684            i + 1 row above and one below */\r
685         for(    mv->dy=poopoffset;      mv->dy<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height;      mv->dy+=mv->map->tiles->tileHeight, ty++) {\r
686                 if(i>=0){\r
687                         mapDrawTile(mv->map->tiles, mv->map->layerdata[0].data[i], mv->page, x, mv->dy);\r
688                         for(z=1;z<=2;z++)\r
689                                 if(mv->map->layerdata[z].data[i]){\r
690                                         sprintf(global_temp_status_text2, "%u", mv->map->layerdata[z].data[i]); modexprint(mv->page, x, mv->dy, 1, 0, PALMAPDRAWW, z+2, 1, global_temp_status_text2);\r
691                                         //mapDrawTile(mv->map->tiles, mv->map->layerdata[z].data[i], mv->page, x, mv->dy);\r
692                                 }\r
693                 }\r
694                 i += mv->map->width;\r
695         }\r
696 #ifdef __DEBUG_RF__\r
697 if(dbg_pagedelayrendermap) delay(200);\r
698 #endif\r
699 }\r
700 \r
701 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)\r
702 {\r
703         int i; nibble z;\r
704 \r
705         /* the position within the map array */\r
706         i=ty * mv->map->width + tx;\r
707         for(mv->dx=0; mv->dx<mv->page->sw+mv->dxThresh && tx < mv->map->width; mv->dx+=mv->map->tiles->tileWidth, tx++) {\r
708                 if(i>=0){       /* we are in the map, so copy! */\r
709                         mapDrawTile(mv->map->tiles, mv->map->layerdata[0].data[i], mv->page, mv->dx, y);\r
710                         for(z=1;z<=2;z++)\r
711                                 if(mv->map->layerdata[z].data[i]){\r
712                                         sprintf(global_temp_status_text2, "%u", mv->map->layerdata[z].data[i]); modexprint(mv->page, mv->dx, y, 1, 0, PALMAPDRAWW, z+2, 1, global_temp_status_text2);\r
713                                         //mapDrawTile(mv->map->tiles, mv->map->layerdata[z].data[i], mv->page, mv->dx, y);\r
714                                 }\r
715                 }\r
716                 i++; /* next! */\r
717         }\r
718 }\r
719 \r
720 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)\r
721 {\r
722         int i; nibble z;\r
723 \r
724         /* location in the map array */\r
725         i=ty * mv->map->width + tx;\r
726 \r
727         /* We'll copy all of the columns in the screen,\r
728            i + 1 row above and one below */\r
729         for(mv->dy=0; mv->dy<mv->page->sh+mv->dyThresh && ty < mv->map->height; mv->dy+=mv->map->tiles->tileHeight, ty++) {\r
730                 if(i>=0){       /* we are in the map, so copy away! */\r
731                         mapDrawTile(mv->map->tiles, mv->map->layerdata[0].data[i], mv->page, x, mv->dy);\r
732                         for(z=1;z<=2;z++)\r
733                                 if(mv->map->layerdata[z].data[i]){\r
734                                         sprintf(global_temp_status_text2, "%u", mv->map->layerdata[z].data[i]); modexprint(mv->page, x, mv->dy, 1, 0, PALMAPDRAWW, z+2, 1, global_temp_status_text2);\r
735                                         //mapDrawTile(mv->map->tiles, mv->map->layerdata[z].data[i], mv->page, x, mv->dy);\r
736                                 }\r
737                 }\r
738                 i += mv->map->width;\r
739         }\r
740 }\r
741 \r
742 \r
743 /*      sync    */\r
744 void shinku(global_game_variables_t *gv)\r
745 {\r
746 #ifdef SHOWFPS\r
747         word x = gv->video.page[/*!*/(gv->video.p)].dx; //(gv->video.page[(gv->video.p)].tlx) - // follow the screen\r
748         word y = gv->video.page[/*!*/(gv->video.p)].dy; //(gv->video.page[(gv->video.p)].tly) - // follow the screen\r
749         word col = 2, bgcol = 1, type = 1;//w = 64, h = 8,\r
750 #endif\r
751         if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))\r
752         {\r
753 #ifdef SHOWFPS\r
754         // NTS: For some bizarre reason, gv->pee is not initialized, but the pointer is not NULL even\r
755         //      though it should be. Instead it's NULL as a neAr pointer but contains a non-null\r
756         //      segment value, so testing against NULL doesn't work. It is initialized properly if\r
757         //      you call start_timer() though which uses neAr mAlloc. Rather than fight with that,\r
758         //      I decided it would be better to declare a temp buffer statically and sprintf to that.\r
759         //\r
760         //      This fixes *** Null pointer assignment detected error message in ZCROLL.EXE on exit.\r
761                 sprintf(global_temp_status_text, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));\r
762                 //modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, 1, col, bgcol, global_temp_status_text);\r
763                 if(gv->kurokku.wcpu)\r
764                 {\r
765                         modexCopyPageRegion(&gv->video.page[0], &gv->video.page[1],\r
766                                 gv->video.page[/*!*/(gv->video.p)].dx,\r
767                                 gv->video.page[/*!*/(gv->video.p)].dy,\r
768                                 gv->video.page[/*!*/(gv->video.p)].dx,\r
769                                 gv->video.page[/*!*/(gv->video.p)].dy,\r
770                                 96, 16);\r
771                         modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, 1, col, 1, bgcol, global_temp_status_text);\r
772 //0000printf("dx=%u     dy=%u\n", gv->video.page[/*!*/(gv->video.p)].dx, gv->video.page[/*!*/(gv->video.p)].dy);\r
773                 }\r
774 #endif\r
775                 gv->kurokku.tiku=0;\r
776         }else //copy dat sheet\r
777         gv->kurokku.tiku++;\r
778 \r
779         switch(gv->kurokku.fpscap)\r
780         {\r
781                 case 0: //turn this off if XT\r
782                         //modexprint(&(gv->video.page[0]), x, y+8, type, 1, col, bgcol, "sanic!");\r
783                         gv->kurokku.frames_per_second=1;\r
784                 break;\r
785                 case 1:\r
786                         //modexWaitBorder();\r
787                         //modexWaitBorder_start();\r
788                         //vga_wait_for_vsync();\r
789                         vga_wait_for_vsync_end();\r
790                         gv->kurokku.frames_per_second=60;\r
791                 break;\r
792         }\r
793         //render!!\r
794         if(gv->video.dorender )\r
795         {//r=1\r
796                 /*if(video->bgp s)\r
797                 {\r
798                         modexCopyPageRegion(&(gv->video.page[ ]), &(gv->video.page[ ]), 0, 0, 0, 0, gv->video.page[ ].width, gv->video.page[ ].height);\r
799                 }else{\r
800                         //modexCopyPageRegion(&video->page[0], &video->page[1], enti->x, enti->y, 0, 0, 24, 32);\r
801                 }*/\r
802                 VL_ShowPage(&(gv->video.page[gv->video.sp]), gv->kurokku.fpscap, 0);\r
803                 gv->video.dorender =!gv->video.dorender;\r
804                 //0000gv->video.tickclk = ((*clockw)-gv->video.startclk)/18.2;\r
805         }\r
806         PM_NextFrame(gv);\r
807 }\r
808 \r
809 void near ZC_animatePlayer(map_view_t *pip, player_t *player, word pn)\r
810 {\r
811         sword x = player[pn].enti.x;\r
812         sword y = player[pn].enti.y;\r
813         sword qq,dd; //scroll offset\r
814         player[pn].enti.dire=10; //direction\r
815 \r
816         switch(player[pn].walktype)\r
817         {\r
818                 case 0:\r
819                         dd = 0;\r
820                         qq = 0;\r
821                 break;\r
822                 case 1:\r
823                         dd = 1;\r
824                         qq = 0;\r
825                 break;\r
826                 case 2:\r
827                         dd = 1;\r
828                         qq = player[pn].enti.q*player[pn].enti.speed;\r
829                 break;\r
830         }\r
831         x-=4;\r
832         y-=pip[0].map->tiles->tileHeight;\r
833         switch (player[pn].enti.d)\r
834         {\r
835                 case 0:\r
836                         //up\r
837                         player[pn].enti.dire*=player[pn].enti.d+1;\r
838                         y-=qq;\r
839                 break;\r
840                 case 3:\r
841                         // right\r
842                         player[pn].enti.dire*=(player[pn].enti.d-1);\r
843                         x+=qq;\r
844                 break;\r
845                 case 2:\r
846                 break;\r
847                 case 4:\r
848                         //down\r
849                         player[pn].enti.dire*=(player[pn].enti.d-1);\r
850                         y+=qq;\r
851                 break;\r
852                 case 1:\r
853                         //left\r
854                         player[pn].enti.dire*=(player[pn].enti.d+3);\r
855                         x-=qq;\r
856                 break;\r
857         }\r
858         player[pn].enti.dire+=dd;\r
859         //setting xy position\r
860         player[pn].enti.spri.x = x;\r
861         player[pn].enti.spri.y = y;\r
862 \r
863         if((player[pn].enti.q==1 && player[pn].enti.pred != player[pn].enti.d) || !dd)//when dir changed OR when player change face direction\r
864         {\r
865                 //0000printf("  q=%u    pred=%u d=%u    dd=%u\n", player[pn].enti.q, player[pn].enti.pred, player[pn].enti.d, dd);\r
866                 set_anim_by_id(&player[pn].enti.spri, player[pn].enti.dire); //pip->video->sprifilei = set_anim_by_id(player[pn].enti.spri, player[pn].enti.dire);      if(pip->video->sprifilei == -1){ printf("ERROR! %u\n", player[pn].enti.dire); return; }\r
867                 player[pn].enti.pred = player[pn].enti.d;\r
868                 if(!dd)//changed direction while NOT moving!\r
869                 {\r
870                         modexCopyPageRegion(pip[0].page, pip[1].page, x-4, y-4, x-4, y-4, 28, 40);\r
871                         animate_spri(&player[pn].enti, pip[0].video);\r
872                 }\r
873         }\r
874 \r
875         if(pip[0].video->vga_state.bgps && dd)//if moving wwww\r
876         {\r
877                 modexCopyPageRegion(pip[0].page, pip[1].page, x-4, y-4, x-4, y-4, 28, 40);\r
878 \r
879                 //draw sprite\r
880                 animate_spri(&player[pn].enti, pip[0].video);\r
881         }\r
882 //0000if(player[pn].enti.q<4) delay(200);\r
883 }\r
884 \r
885 /*\r
886  * from zcroll16.c\r
887 */\r
888 \r
889 boolean boundary_check(int x, int y, int dx, int dy, int h, int w)\r
890 {\r
891         return (dx > 0 && (x + dx) < w) || (dx < 0 && (x + dx) >= 0) || (dy > 0 && (y + dy) < h) || (dy < 0 && (y + dy) >= 0) || (dx == dy && dx == 0);\r
892 }\r
893 \r
894 boolean coll_check(int x, int y, int dx, int dy, map_view_t *map_v)\r
895 {\r
896         // Assume everything crosses at most 1 tile at once\r
897         return dx && 1;//crossable_tile(x + dx, map_v) || dy && crossable_tile(y + dy, map_v);\r
898 }\r
899 \r
900 boolean ZC_walk2(entity_t *enti, map_view_t *map_v)\r
901 {\r
902         //return 1;\r
903         int dx = 1;\r
904         int dy = 1;\r
905         switch(enti->d)\r
906         {\r
907                 case 2:\r
908                         return 0;\r
909                 case 1:\r
910                         dx = -dx;\r
911                 case 3:\r
912                         dy = 0;\r
913                         break;\r
914                 case 0:\r
915                         dy = -dy;\r
916                 case 4:\r
917                         dx = 0;\r
918                         break;\r
919         }\r
920         if(coll_check(enti->x, enti->y, dx, dy,  map_v))\r
921         {\r
922                 // Allow movement\r
923                 // Set speed\r
924                 // Start animation\r
925                 // Mark next tile as occupied\r
926                 // Mark this tile as vacant\r
927                 return 1;\r
928         }\r
929         return 0;\r
930 }\r
931 \r
932 void player_walk(player_t *player, map_view_t *map_v){\r
933         int dx=16, dy=16;\r
934         if(ZC_walk2(&(player->enti), map_v) && boundary_check(map_v->tx, map_v->ty, dx, dy, map_v->map->width - 2*map_v->page->ti.tilesw, map_v->map->height - 2*map_v->page->ti.tilesh))\r
935         {\r
936                 mapScroll(map_v, player);\r
937                 // (Un)load stuff?\r
938         }\r
939 }\r
940 \r
941 /*\r
942  *      end\r
943  */\r
944 \r
945 void mapScroll(map_view_t *mv, player_t *player)\r
946 {\r
947         //word x, y;  /* coordinate for drawing */\r
948         int c = 1;\r
949         int delta;\r
950         mv->delta += player->dx | player->dy;\r
951         delta = mv->delta;\r
952         mv->d = (player->dx) ? (player->dx > 0) ? 3 : 1 : (player->dy) ? (player->dy > 0) ? 4 : 0 : 2;\r
953         switch(mv->d){\r
954                 case 4:\r
955                         c = -1;\r
956                         delta = -delta;\r
957                 case 0:\r
958                         if(!(delta + mv->dxThresh))\r
959                         {\r
960                                 mv->delta = 0;\r
961                                 mv->ty += c;\r
962                         }\r
963                         break;\r
964                 case 3:\r
965                         c = -1;\r
966                         delta = -delta;\r
967                 case 1:\r
968                         if(!(delta + mv->dyThresh))\r
969                         {\r
970                                 mv->delta = 0;\r
971                                 mv->tx += c;\r
972                         }\r
973                         break;\r
974                 default:\r
975                         break;\r
976         }\r
977 }\r