]> 4ch.mooo.com Git - 16.git/blob - src/lib/scroll16.c
polished 16_vrs.h and put into make file AND! updated copyright to add yakui lover...
[16.git] / src / lib / scroll16.c
1 /* Project 16 Source Code~
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
3  *
4  * This file is part of Project 16.
5  *
6  * Project 16 is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Project 16 is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,
19  * Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  */
22 /*
23         scroll16 library~
24 */
25 #include "src/lib/scroll16.h"
26
27 void walk(map_view_t *pip, player_t *player, word pn)
28 {
29         #define INC_PER_FRAME if(player[pn].q&1) player[pn].persist_aniframe++; if(player[pn].persist_aniframe>4) player[pn].persist_aniframe = 1;
30         //printf("player[%d].d=%d\n", pn, player[pn].d);
31         switch(player[pn].d)
32         {
33                 //no direction
34                 case 2:
35                         //0000pip[0].video->startclk = (*clockw);
36                 break;
37                 //right movement
38                 case 3:
39                         //printf("pip[0].page->tilesw=%d        ", pip[0].page->tilesw); printf("pip[0].page->tw=%d\n", pip[0].page->tw);
40                         if(pip[0].tx >= 0 && pip[0].tx+pip[0].page->tw < pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
41                         !(pip[0].map->data[(player[pn].tx)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx+1 == TRIGGX && player[pn].ty == TRIGGY))      //collision detection!
42                         {
43                                 if(player[pn].q<=player[pn].spt)
44                                 {
45                                         INC_PER_FRAME;
46                                         animatePlayer(pip, player, pn, 1);
47                                         ScrollRight(pip, player, 3, pn);
48                                         ScrollRight(pip, player, 2, pn);
49                                         mapScrollRight(pip, player, !(pip[0].video->p), pn);
50                                         mapScrollRight(pip, player, (pip[0].video->p), pn);
51                                         if(!pageflipflop) modexShowPage(pip[1].page);
52                                         player[pn].q++;
53                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
54                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
55                         }
56                         else if(player[pn].tx < pip[0].map->width && !(pip[0].map->data[(player[pn].tx)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx+1 == TRIGGX && player[pn].ty == TRIGGY))
57                         {
58                                 if(player[pn].q<=player[pn].spt)
59                                 {
60                                         INC_PER_FRAME;
61                                         player[pn].x+=(player[pn].speed);
62                                         animatePlayer(pip, player, pn, 0);
63                                         if(!pageflipflop) modexShowPage(pip[1].page);
64                                         player[pn].q++;
65                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx++; }
66                         }
67                         else
68                         {
69                                 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
70 #ifdef SPRITE
71                                 PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 16, 32, PLAYERBMPDATA);
72 #else
73                                 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 14);
74 #endif
75                                 if(!pageflipflop) modexShowPage(pip[1].page);
76                                 player[pn].d = 2;
77                         }
78                         player[pn].triggerx = player[pn].tx+1;
79                         player[pn].triggery = player[pn].ty;
80                 break;
81
82                 //left movement
83                 case 1:
84                         if(pip[0].tx > 0 && pip[0].tx+pip[0].page->tw <= pip[0].map->width && player[pn].tx == pip[0].tx+pip[0].page->tilemidposscreenx &&
85                         !(pip[0].map->data[(player[pn].tx-2)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx-1 == TRIGGX && player[pn].ty == TRIGGY))    //collision detection!
86                         {
87                                 if(player[pn].q<=player[pn].spt)
88                                 {
89                                         INC_PER_FRAME;
90                                         animatePlayer(pip, player, pn, 1);
91                                         ScrollLeft(pip, player, 3, pn);
92                                         ScrollLeft(pip, player, 2, pn);
93                                         mapScrollLeft(pip, player, !(pip[0].video->p), pn);
94                                         mapScrollLeft(pip, player, (pip[0].video->p), pn);
95                                         if(!pageflipflop) modexShowPage(pip[1].page);
96                                         player[pn].q++;
97                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
98                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
99                         }
100                         else if(player[pn].tx > 1 && !(pip[0].map->data[(player[pn].tx-2)+(pip[0].map->width*(player[pn].ty-1))] == 0))//!(player[pn].tx-1 == TRIGGX && player[pn].ty == TRIGGY))
101                         {
102                                 if(player[pn].q<=player[pn].spt)
103                                 {
104                                         INC_PER_FRAME;
105                                         player[pn].x-=(player[pn].speed);
106                                         animatePlayer(pip, player, pn, 0);
107                                         if(!pageflipflop) modexShowPage(pip[1].page);
108                                         player[pn].q++;
109                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].tx--; }
110                         }
111                         else
112                         {
113                                 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
114 #ifdef SPRITE
115                                 PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 96, 16, 32, PLAYERBMPDATA);
116 #else
117                                 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 10);
118 #endif
119                                 if(!pageflipflop) modexShowPage(pip[1].page);
120                                 player[pn].d = 2;
121                         }
122                         player[pn].triggerx = player[pn].tx-1;
123                         player[pn].triggery = player[pn].ty;
124                 break;
125
126                 //down movement
127                 case 4:
128                         if(pip[0].ty >= 0 && pip[0].ty+pip[0].page->th < pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
129                         !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty+1 == TRIGGY))      //collision detection!
130                         {
131                                 if(player[pn].q<=player[pn].spt)
132                                 {
133                                         INC_PER_FRAME;
134                                         animatePlayer(pip, player, pn, 1);
135                                         ScrollDown(pip, player, 3, pn);
136                                         ScrollDown(pip, player, 2, pn);
137                                         mapScrollDown(pip, player, !(pip[0].video->p), pn);
138                                         mapScrollDown(pip, player, (pip[0].video->p), pn);
139                                         if(!pageflipflop) modexShowPage(pip[1].page);
140                                         player[pn].q++;
141                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
142                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
143                         }
144                         else if(player[pn].ty < pip[0].map->height && !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty+1 == TRIGGY))
145                         {
146                                 if(player[pn].q<=player[pn].spt)
147                                 {
148                                         INC_PER_FRAME;
149                                         player[pn].y+=(player[pn].speed);
150                                         animatePlayer(pip, player, pn, 0);
151                                         if(!pageflipflop) modexShowPage(pip[1].page);
152                                         player[pn].q++;
153                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty++; }
154                         }
155                         else
156                         {
157                                 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
158 #ifdef SPRITE
159                                 PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 64, 16, 32, PLAYERBMPDATA);
160 #else
161                                 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 9);
162 #endif
163                                 if(!pageflipflop) modexShowPage(pip[1].page);
164                                 player[pn].d = 2;
165                         }
166                         player[pn].triggerx = player[pn].tx;
167                         player[pn].triggery = player[pn].ty+1;
168                 break;
169
170                 //up movement
171                 case 0:
172                         if(pip[0].ty > 0 && pip[0].ty+pip[0].page->th <= pip[0].map->height && player[pn].ty == pip[0].ty+pip[0].page->tilemidposscreeny &&
173                         !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty-2))] == 0))//!(player[pn].tx == TRIGGX && player[pn].ty-1 == TRIGGY))    //collision detection!
174                         {
175                                 if(player[pn].q<=player[pn].spt)
176                                 {
177                                         INC_PER_FRAME;
178                                         animatePlayer(pip, player, pn, 1);
179                                         ScrollUp(pip, player, 3, pn);
180                                         ScrollUp(pip, player, 2, pn);
181                                         mapScrollUp(pip, player, !(pip[0].video->p), pn);
182                                         mapScrollUp(pip, player, (pip[0].video->p), pn);
183                                         if(!pageflipflop) modexShowPage(pip[1].page);
184                                         player[pn].q++;
185                                         //0000pip[0].video->clk = ((*clockw)-pip[0].video->startclk)/18.2;
186                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
187                         }
188                         else if(player[pn].ty > 1 && !(pip[0].map->data[(player[pn].tx-1)+(pip[0].map->width*(player[pn].ty-2))] == 0))//!(player[pn].tx == TRIGGX &&  player[pn].ty-1 == TRIGGY))
189                         {
190                                 if(player[pn].q<=player[pn].spt)
191                                 {
192                                         INC_PER_FRAME;
193                                         player[pn].y-=(player[pn].speed);
194                                         animatePlayer(pip, player, 0, pn);
195                                         if(!pageflipflop) modexShowPage(pip[1].page);
196                                         player[pn].q++;
197                                 } else { player[pn].q = 1; player[pn].d = 2; player[pn].ty--; }
198                         }
199                         else
200                         {
201                                 if(!pageflipflop) modexCopyPageRegion(pip[1].page, pip[0].page, player[pn].x, player[pn].y-TILEWH, player[pn].x, player[pn].y-TILEWH, 16, 32);
202 #ifdef SPRITE
203                                 PBUFSFUN(pip[0].page, player[pn].x, player[pn].y-TILEWH, 16, 0, 16, 32, PLAYERBMPDATA);
204 #else
205                                 modexClearRegion(pip[1].page, player[pn].x, player[pn].y-TILEWH, 16, 32, 12);
206 #endif
207                                 if(!pageflipflop) modexShowPage(pip[1].page);
208                                 player[pn].d = 2;
209                         }
210                         player[pn].triggerx = player[pn].tx;
211                         player[pn].triggery = player[pn].ty-1;
212                 break;
213         }
214 }
215
216 //panning page
217 void panpagemanual(map_view_t *pip, player_t *player, word pn)
218 {
219         switch(player[pn].d)
220         {
221                 //right movement
222                 case 3:
223                         if(pip[pip[0].pan->pn].tx >= 0 && pip[pip[0].pan->pn].tx+pip[pip[0].pan->pn].page->tw < pip[pip[0].pan->pn].page->tilesw)
224                         {
225                                 if(player[pn].q<=player[pn].spt)
226                                 {
227                                         pip[pip[0].pan->pn].page->dx+=4;
228                                         modexShowPage(pip[pip[0].pan->pn].page);
229                                         player[pn].q++;
230                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx++; }
231                         }
232                 break;
233
234                 //left movement
235                 case 1:
236                         if(pip[pip[0].pan->pn].tx > 0 && pip[pip[0].pan->pn].tx+pip[pip[0].pan->pn].page->tw <= pip[pip[0].pan->pn].page->tilesw)
237                         {
238                                 if(player[pn].q<=player[pn].spt)
239                                 {
240                                         pip[pip[0].pan->pn].page->dx-=4;
241                                         modexShowPage(pip[pip[0].pan->pn].page);
242                                         player[pn].q++;
243                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].tx--; }
244                         }
245                 break;
246
247                 //down movement
248                 case 4:
249                         if(pip[pip[0].pan->pn].ty >= 0 && pip[pip[0].pan->pn].ty+pip[pip[0].pan->pn].page->th < pip[pip[0].pan->pn].page->tilesh)
250                         {
251                                 if(player[pn].q<=player[pn].spt)
252                                 {
253                                         pip[pip[0].pan->pn].page->dy+=4;
254                                         modexShowPage(pip[pip[0].pan->pn].page);
255                                         player[pn].q++;
256                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty++; }
257                         }
258                 break;
259
260                 //up movement
261                 case 0:
262                         if(pip[pip[0].pan->pn].ty > 0 && pip[pip[0].pan->pn].ty+pip[pip[0].pan->pn].page->th <= pip[pip[0].pan->pn].page->tilesh)
263                         {
264                                 if(player[pn].q<=player[pn].spt)
265                                 {
266                                         pip[pip[0].pan->pn].page->dy-=4;
267                                         modexShowPage(pip[pip[0].pan->pn].page);
268                                         player[pn].q++;
269                                 } else { player[pn].q = 1; player[pn].d = 2; pip[pip[0].pan->pn].ty--; }
270                         }
271                         break;
272         }
273         //if (player[pn].d!=2) printf("player[%u].d=%u player[%u].q=%u\n", pn, player[pn].d, pn, player[pn].q);
274 }
275
276 /*map_t
277 allocMap(int w, int h) {
278         map_t result;
279
280         result.width =w;
281         result.height=h;
282         result.data = malloc(sizeof(byte) * w * h);
283         //result.data = (byte *)alloc_emem(((int)sizeof(byte) * w * h)/1024);
284         if(isEMS() || checkEMS())
285         {
286                 XMOVE mm;
287                 //emmhandle = mallocEMS(coretotalEMS());//alloc_emem((int)sizeof(map))
288                 mm.length=sizeof(result);
289                 mm.sourceH=0;
290                 mm.sourceOff=ptr2long(&result);
291                 mm.destH=emmhandle;
292                 mm.destOff=0;
293                 ist = move_emem(&mm);
294                 if(!ist){ dealloc_emem(emmhandle); exit(5); }
295                 printf("%d\n", coretotalEMS());
296         }
297
298         return result;
299 }*/
300
301 /*void
302 initMap(map_t *map) {
303         // just a place holder to fill out an alternating pattern
304         int x, y, xx, yy;
305         int i, q;
306 //      int tile = 1;
307         //if(!isEMS() || !checkEMS())
308 //              map->tiles = malloc(sizeof(tiles_t));
309         //else
310         //      map->tiles = (tiles_t *)alloc_emem(sizeof(tiles_t));
311
312          //create the tile set
313         //if(!isEMS() || !checkEMS())
314 //              map->tiles->data = malloc(sizeof(bitmap_t));
315         //else
316         //      map->tiles->data = (bitmap_t *)alloc_emem(sizeof(bitmap_t));
317 //      map->tiles->data->width = (TILEWH);
318 //      map->tiles->data->height= TILEWH;
319         //if(!isEMS() || !checkEMS())
320 //              map->tiles->data->data = malloc((TILEWH*2)*TILEWH);
321         //else
322         //      map->tiles->data->data = (byte *)alloc_emem((TILEWH*2)*TILEWH);
323 //      map->tiles->tileHeight = TILEWH;
324 //      map->tiles->tileWidth =TILEWH;
325 //      map->tiles->rows = 1;
326 //      map->tiles->cols = 1;//2;
327
328         q=0;
329         //for(y=0; y<map->height; y++) {
330         //for(x=0; x<map->width; x++) {
331         i=0;
332         for(yy=0; yy<TILEWH; yy++) {
333         for(xx=0; xx<(TILEWH); xx++) {
334                 //if(x<TILEWH){
335                   map->tiles->data->data[i+1] = map->data[q];//28;//0x24;
336 //                printf("[%d]", map->tiles->data->data[i]);
337                 //}else{
338                   //map->tiles->data->data[i] = map->data[q];//0;//0x34;
339                   //printf("]%d[==[%d]", i, map->tiles->data->data[i]);
340                 //}
341                 i++;
342         }
343 //      printf("\n");
344         }
345 //      printf("[%d]", map->data[q]);
346         q++;
347 //      }
348         //printf("\n\n");
349 //      }
350
351         i=0;
352         for(y=0; y<map->height; y++) {
353                 for(x=0; x<map->width; x++) {
354 //                      map->data[i]=255;
355                         printf("[%d]", map->data[i]);
356                         //tile = tile ? 0 : 1;
357                         i++;
358                 }
359                 //tile = tile ? 0 : 1;
360         }
361 }*/
362
363 void near mapScrollRight(map_view_t *mv, player_t *player, word id, word plid)
364 {
365         word x, y;  /* coordinate for drawing */
366
367         /* increment the pixel position and update the page */
368         mv[id].page->dx += player[plid].speed;
369
370         /* check to see if this changes the tile */
371         if(mv[id].page->dx >= mv[id].dxThresh )
372         {
373         /* go forward one tile */
374         mv[id].tx++;
375         /* Snap the origin forward */
376         mv[id].page->data += 4;
377
378         mv[id].page->dx = mv[id].map->tiles->tileWidth;
379         }
380
381         /* draw the next column */
382         x= mv[0].page->sw + mv[id].map->tiles->tileWidth;
383         if(player[plid].q%4)
384                 if(id==0)
385                         mapDrawCol(&mv[0], mv[0].tx + mv[0].page->tw, mv[0].ty-1, x, player, mv->page->dx);
386                 else
387                         if(!pageflipflop && !pageploop)
388                                 modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->th+2));
389         mv[0].video->r=1;
390 }
391
392
393 void near mapScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
394 {
395         word x, y;  /* coordinate for drawing */
396
397         /* decrement the pixel position and update the page */
398         mv[id].page->dx -= player[plid].speed;
399
400         /* check to see if this changes the tile */
401         if(mv[id].page->dx == 0)
402         {
403         /* go backward one tile */
404         mv[id].tx--;
405         /* Snap the origin backward */
406         mv[id].page->data -= 4;
407
408         mv[id].page->dx = mv[id].map->tiles->tileWidth;
409         }
410
411         /* draw the next column */
412         x= 0;
413         if(player[plid].q%4)
414                 if(id==0)
415                         mapDrawCol(&mv[0], mv[0].tx - 1, mv[0].ty-1, x, player, mv->page->dx);
416                 else
417                         if(!pageflipflop && !pageploop)
418                                 modexCopyPageRegion(mv[id].page, mv[0].page, x, 0, x, 0, mv[id].map->tiles->tileWidth, mv[id].map->tiles->tileHeight*(mv[0].page->th+2));
419         mv[0].video->r=1;
420 }
421
422
423 void near mapScrollUp(map_view_t *mv, player_t *player, word id, word plid)
424 {
425         word x, y;  /* coordinate for drawing */
426
427         /* decrement the pixel position and update the page */
428         mv[id].page->dy -= player[plid].speed;
429
430         /* check to see if this changes the tile */
431         if(mv[id].page->dy == 0 )
432         {
433         /* go down one tile */
434         mv[id].ty--;
435         /* Snap the origin downward */
436         mv[id].page->data -= mv[id].page->pi;
437
438         mv[id].page->dy = mv[id].map->tiles->tileHeight;
439         }
440
441         /* draw the next row */
442         y= 0;
443         if(player[plid].q%3)
444                 if(id==0)
445                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty-1, y, player, mv->page->dy);
446                 else
447                         if(!pageflipflop && !pageploop)
448                                 modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tw+2), mv[id].map->tiles->tileHeight);
449         mv[0].video->r=1;
450 }
451
452 void near mapScrollDown(map_view_t *mv, player_t *player, word id, word plid)
453 {
454         word x, y;  /* coordinate for drawing */
455
456         /* increment the pixel position and update the page */
457         mv[id].page->dy += player[plid].speed;
458
459         /* check to see if this changes the tile */
460         if(mv[id].page->dy >= mv[id].dyThresh )
461         {
462         /* go down one tile */
463         mv[id].ty++;
464         /* Snap the origin downward */
465         mv[id].page->data += mv[id].page->pi;
466
467         mv[id].page->dy = mv[id].map->tiles->tileHeight;
468         }
469
470         /* draw the next row */
471         y= mv[0].page->sh + mv[id].map->tiles->tileHeight;
472         if(player[plid].q%3)
473                 if(id==0)
474                         mapDrawRow(&mv[0], mv[0].tx - 1, mv[0].ty+mv[0].page->th, y, player, mv->page->dy);
475                 else
476                         if(!pageflipflop && !pageploop)
477                                 modexCopyPageRegion(mv[id].page, mv[0].page, 0, y, 0, y, mv[id].map->tiles->tileWidth*(mv[0].page->tw+2), mv[id].map->tiles->tileHeight);
478         mv[0].video->r=1;
479 }
480
481
482 //TODO finish this wwww
483 void near ScrollRight(map_view_t *mv, player_t *player, word id, word plid)
484 {
485         /* increment the pixel position and update the page */
486         mv[id].page->dx += player[plid].speed;
487
488         /* check to see if this changes the tile */
489         if(mv[id].page->dx >= mv[0].dxThresh )
490         {
491 //              vga_setup_wm1_block_copy();
492 //              _fmemmove(mv[id].page->data+4, mv[id].page->data, mv[id].page->pagesize);
493 //              vga_restore_rm0wm0();
494                 /* Snap the origin forward */
495                 mv[id].page->data += 4;
496                 mv[id].page->dx = mv[0].map->tiles->tileWidth;
497         }
498 }
499
500 void near ScrollLeft(map_view_t *mv, player_t *player, word id, word plid)
501 {
502         /* decrement the pixel position and update the page */
503         mv[id].page->dx -= player[plid].speed;
504
505         /* check to see if this changes the tile */
506         if(mv[id].page->dx == 0)
507         {
508 //              vga_setup_wm1_block_copy();
509 //              _fmemmove(mv[id].page->data-4, mv[id].page->data, mv[id].page->pagesize);
510 //              vga_restore_rm0wm0();
511                 /* Snap the origin backward */
512                 mv[id].page->data -= 4;
513                 mv[id].page->dx = mv[0].map->tiles->tileWidth;
514         }
515 }
516
517 void near ScrollUp(map_view_t *mv, player_t *player, word id, word plid)
518 {
519         /* decrement the pixel position and update the page */
520         mv[id].page->dy -= player[plid].speed;
521
522         /* check to see if this changes the tile */
523         if(mv[id].page->dy == 0)
524         {
525 //              vga_setup_wm1_block_copy();
526 //              _fmemmove(mv[id].page->data-mv[id].page->pi, mv[id].page->data, mv[id].page->pagesize);
527 //              vga_restore_rm0wm0();
528                 /* Snap the origin backward */
529                 mv[id].page->data -= mv[id].page->pi;
530                 mv[id].page->dy = mv[0].map->tiles->tileWidth;
531         }
532 }
533
534 void near ScrollDown(map_view_t *mv, player_t *player, word id, word plid)
535 {
536         /* increment the pixel position and update the page */
537         mv[id].page->dy += player[plid].speed;
538
539         /* check to see if this changes the tile */
540         if(mv[id].page->dy >= mv[0].dxThresh )
541         {
542 //              vga_setup_wm1_block_copy();
543 //              _fmemmove(mv[id].page->data+mv[id].page->pi, mv[id].page->data, mv[id].page->pagesize);
544 //              vga_restore_rm0wm0();
545                 /* Snap the origin forward */
546                 mv[id].page->data += mv[id].page->pi;
547                 mv[id].page->dy = mv[0].map->tiles->tileWidth;
548         }
549 }
550
551 sword chkmap(map_t *map, word q)
552 {
553 //      bitmap_t bp;
554         static byte x[(MAPW*MAPH)+1] =
555 { 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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, 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 };
556 /*1,    2,      3,      4,      0,      3,      3,      3,      3,      3,      3,      3,      3,      4,      1,      1,      1,      1,      1,      1,      \
557 5,      6,      7,      8,      0,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
558 9,      10,     11,     12,     4,      1,      0,      1,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
559 13,     14,     15,     16,     0,      1,      1,      1,      5,      8,      1,      11,     11,     1,      1,      1,      1,      1,      1,      1,      \
560 0,      0,      4,      0,      0,      0,      0,      0,      8,      8,      1,      11,     11,     3,      1,      1,      1,      1,      1,      1,      \
561 1,      1,      1,      1,      0,      0,      0,      0,      8,      8,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
562 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
563 1,      1,      1,      1,      0,      0,      0,      0,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
564 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
565 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
566 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
567 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
568 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      1,      1,      1,      \
569 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      \
570 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      3,      3,      3,      3,      1,      2,      3,      4 };*/
571         //check for failed to load map
572         if((map->width == map->height == 0) && (q>0))
573         {
574                 //initiate a null map!
575                 map->width=MAPW;///2;
576                 map->height=MAPH;///2;
577 //              map->data = malloc(((map->width*map->height)+1)*sizeof(byte));
578                 map->data = &x;
579                 map->tiles = malloc(sizeof(tiles_t));
580                 //fix this to be far~
581 //              bp = bitmapLoadPcx("data/ed.pcx");
582 //              map->tiles->data = &bp;
583                 map->tiles->debug_data = map->data;
584                 map->tiles->tileHeight = 16;
585                 map->tiles->tileWidth = 16;
586                 map->tiles->rows = 1;
587                 map->tiles->cols = 1;
588                 map->tiles->debug_text = true;
589         }
590         else map->tiles->debug_text = false;
591         return 0;
592 }
593
594 //TODO: player position here
595 void mapGoTo(map_view_t *mv, int tx, int ty)
596 {
597         int px, py;
598         unsigned int i;
599
600         /* set up the coordinates */
601         mv[0].tx = mv[1].tx = tx;
602         mv[0].ty = mv[1].ty = ty;
603         mv[0].page->dx = mv[1].page->dx = mv[2].page->dx = mv[3].page->dx = mv->map->tiles->tileWidth;
604         mv[0].page->dy = mv[1].page->dy = mv[2].page->dy = mv[3].page->dy = mv->map->tiles->tileHeight;
605
606         /* set up the thresholds */
607         mv[0].dxThresh = mv[1].dxThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileWidth * 2;
608         mv[0].dyThresh = mv[1].dyThresh = mv[2].dxThresh = mv[3].dxThresh = mv->map->tiles->tileHeight * 2;
609
610         /* draw the tiles */
611         modexClearRegion(mv[0].page, 0, 0, mv[0].page->width, mv[0].page->height, 0);
612         py=0;
613         i=mv[0].ty * mv[0].map->width + mv[0].tx;
614         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) {
615                 mapDrawWRow(&mv[0], tx-1, ty, py);
616         i+=mv->map->width - tx;
617         }
618         if(!pageploop) modexCopyPageRegion(mv[1].page, mv[0].page, 0, 0, 0, 0, mv[0].page->width, mv[0].page->height);
619 //      {
620 //              unsigned int k,j,o;
621 //              /* fill screen with a distinctive pattern */
622 //              for (k=0;k < vga_state.vga_width;k++) {
623 //                      o = k >> 2;
624 //                      vga_write_sequencer(0x02/*map mask*/,1 << (k&3));
625 //                              for (j=0;j < (mv[0].page->height)+(mv[1].page->height)+(mv[2].page->height)+(mv[3].page->height);j++,o += vga_state.vga_stride)
626 //                                      vga_state.vga_graphics_ram[o] = (k^j)&15; // VRL samples put all colors in first 15!
627 //              }
628 //      }
629         modexCopyPageRegion(mv[3].page, mv[0].page, 0/**/, 0/**/, 0, 0, 16, 32);
630 }
631
632 void near
633 mapDrawTile(tiles_t *t, word i, page_t *page, word x, word y)
634 {
635         word rx;
636         word ry;
637         word textx=0;
638         word texty=0;
639         //if(i==0) i=2;
640         if(i==0)
641         {
642                 //wwww
643                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, 0); //currently the over scan color!
644         }
645         else
646         {
647                 rx = (((i-1) % ((t->data->width)/t->tileWidth)) * t->tileWidth);
648                 ry = (((i-1) / ((t->data->height)/t->tileHeight)) * t->tileHeight);
649 ////0000printf("i=%d\n", i);
650                 switch(t->debug_text)
651                 {
652                         case 0:
653 #ifndef TILERENDER
654                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, ((t->debug_data[i])+1));
655                                 //modexprint(page, x, y, 1, 15, 0, (char const *)(t->debug_data[i]));
656 #else
657                                 PBUFBFUN                (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
658                                 /* then the sprite. note modding ram ptr means we just draw to (x&3,0) */
659                                 //draw_vrl1_vgax_modex(x-rx,y-ry,vrl_header,vrl_lineoffs,buffer+sizeof(*vrl_header),bufsz-sizeof(*vrl_header));
660                                 //modexDrawBmpRegion    (page, x, y, rx, ry, t->tileWidth, t->tileHeight, (t->data));
661 #endif
662                         break;
663                         case 1:
664                                 modexClearRegion(page, x, y, t->tileWidth, t->tileHeight, (t->debug_data[i])+1);
665                                 //modexprintbig(page, x, y, 1, 15, 0, (t->debug_data));
666                                 /*for(texty=0; texty<2; texty++)
667                                 {
668                                         for(textx=0; textx<2; textx++)
669                                         {*/
670 //                                              modexprint(page, x+(textx*8), y+(texty*8), 1, (word)(t->debug_data), 0, (t->debug_data));
671 /*                                      }
672                                 }*/
673                         break;
674                 }
675         }
676 }
677
678 void near mapDrawRow(map_view_t *mv, int tx, int ty, word y, player_t *p, word poopoffset)
679 {
680         word x;
681         int i;
682         poopoffset%=p[0].speed;
683 //printf("y: %d\n", poopoffset);
684         /* the position within the map array */
685         i=ty * mv->map->width + tx;
686         for(x=poopoffset; x<(mv->page->sw+mv->dxThresh)/(poopoffset+1) && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
687         if(i>=0) {
688                 /* we are in the map, so copy! */
689                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
690         }
691         i++; /* next! */
692         }
693 }
694
695 void near mapDrawCol(map_view_t *mv, int tx, int ty, word x, player_t *p, word poopoffset)
696 {
697         int y;
698         int i;
699         poopoffset%=p[0].speed;
700 //printf("x: %d\n", poopoffset);
701         /* location in the map array */
702         i=ty * mv->map->width + tx;
703
704         /* We'll copy all of the columns in the screen,
705            i + 1 row above and one below */
706         for(y=poopoffset; y<(mv->page->sh+mv->dyThresh)/(poopoffset+1) && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
707         if(i>=0) {
708                 /* we are in the map, so copy away! */
709                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
710         }
711         i += mv->map->width;
712         }
713 }
714
715 void mapDrawWRow(map_view_t *mv, int tx, int ty, word y)
716 {
717         word x;
718         int i;
719
720         /* the position within the map array */
721         i=ty * mv->map->width + tx;
722         for(x=0; x<mv->page->sw+mv->dxThresh && tx < mv->map->width; x+=mv->map->tiles->tileWidth, tx++) {
723         if(i>=0) {
724                 /* we are in the map, so copy! */
725                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
726         }
727         i++; /* next! */
728         }
729 }
730
731 void mapDrawWCol(map_view_t *mv, int tx, int ty, word x)
732 {
733         int y;
734         int i;
735
736         /* location in the map array */
737         i=ty * mv->map->width + tx;
738
739         /* We'll copy all of the columns in the screen,
740            i + 1 row above and one below */
741         for(y=0; y<mv->page->sh+mv->dyThresh && ty < mv->map->height; y+=mv->map->tiles->tileHeight, ty++) {
742         if(i>=0) {
743                 /* we are in the map, so copy away! */
744                 mapDrawTile(mv->map->tiles, mv->map->data[i], mv->page, x, y);
745         }
746         i += mv->map->width;
747         }
748 }
749
750 /*void qclean()
751 {
752         //setkb(0);
753 }*/
754
755 unsigned char shinku_fps_indicator_page = 2;
756 boolean pageflipflop;
757 boolean pageploop = 1;
758
759 /*      sync    */
760 void shinku(global_game_variables_t *gv)
761 {
762         word x = (0) + gv->video.page[/*!*/(gv->video.p)].dx; // follow the screen
763         word y = (0) + gv->video.page[/*!*/(gv->video.p)].dy; // follow the screen
764         word w = 64, h = 8, col = 7, bgcol = 0, type = 1;
765         byte o,o2,i;
766         //modexCopyPageRegion(pip[1].page, pip[2].page, 16, 16, 16, 16, (14*8)+4, 8+4);
767         /* block copy to visible RAM from offscreen */
768 //      vga_setup_wm1_block_copy();
769 //      modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x+w, 0, w, h);
770 //      o =     *(gv->video.page[2].data); // source offscreen
771 //      o2 =    *(gv->video.page[shinku_fps_indicator_page].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
772 //      for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += vga_state.vga_stride) vga_wm1_mem_block_copy(o2,o,w >> 2);
773         /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
774 //      vga_restore_rm0wm0();
775         if(elapsed_timer(gv) >= (1.0 / gv->kurokku.frames_per_second))
776         {
777                 sprintf(gv->pee, "%.0f fps", (double)gv->kurokku.tiku/ticktock(gv));
778                 //modexClearRegion(&(gv->video.page[shinku_fps_indicator_page]), x, y, w, h, 45);
779                 modexprint(&(gv->video.page[/*!*/(gv->video.p)]), x, y, type, col, bgcol, gv->pee);
780                 gv->kurokku.tiku=0;
781                 /* block copy to visible RAM from offscreen */
782 //              vga_setup_wm1_block_copy();
783 //              o =     *(gv->video.page[shinku_fps_indicator_page].data); // source offscreen
784 //              o2 =    *(gv->video.page[2].data)+(y * vga_state.vga_stride) + (x >> 2); // dest visible (original stride)
785 //              for (i=0;i < h;i++,o += vga_state.vga_draw_stride,o2 += vga_state.vga_stride) vga_wm1_mem_block_copy(o2,o,w >> 2);
786 //              modexCopyPageRegion(&(gv->video.page[shinku_fps_indicator_page]), &(gv->video.page[!shinku_fps_indicator_page]), x, y, x, 0, w, h);
787                 /* must restore Write Mode 0/Read Mode 0 for this code to continue drawing normally */
788 //              vga_restore_rm0wm0();
789         }else //copy dat sheet
790         gv->kurokku.tiku++;
791
792         switch(gv->kurokku.fpscap)
793         {
794                 case 0:
795                         //modexprint(&(gv->video.page[shinku_fps_indicator_page]), x, y+8, type, col, bgcol, "sanic!");
796                         gv->kurokku.frames_per_second=1;
797                 break;
798                 case 1:
799                         //turn this off if XT
800                         //modexWaitBorder();
801                         vga_wait_for_vsync();
802                         gv->kurokku.frames_per_second=60;
803                 break;
804         }
805         if(pageflipflop){
806         if(gv->video.r){
807                 //vga_setup_wm1_block_copy();
808                 //_fmemcpy((gv->video.page[(gv->video.p)]).data, (gv->video.page[(!gv->video.p)]).data, gv->video.page[(!gv->video.p)].pagesize);
809                 //vga_restore_rm0wm0();
810                 if(!pageploop) modexCopyPageRegion(&(gv->video.page[(gv->video.p)]), &(gv->video.page[(!gv->video.p)]), 0, 0, 0, 0, gv->video.page[gv->video.p].width, gv->video.page[!gv->video.p].height);
811                 modexShowPage(&(gv->video.page[gv->video.p]));
812                 if(!pageploop) gv->video.p=!gv->video.p;
813                 gv->video.r=!gv->video.r;
814                 //0000gv->video.tickclk = ((*clockw)-gv->video.startclk)/18.2;
815         }
816         }
817 }
818
819 void near animatePlayer(map_view_t *pip, player_t *player, word pn, sword scrollswitch)
820 {
821         sword x = player[pn].x;
822         sword y = player[pn].y;
823         sword bx = x+16;        //buffer's x
824         sword by = y+16;        //buffer's y
825         word dire=32; //direction
826         sword qq; //scroll offset
827         word ls = player[pn].persist_aniframe;
828
829         switch(scrollswitch)
830         {
831                 case 0:
832                         qq = 0;
833                 break;
834                 default:
835                         qq = ((player[pn].q)*(player[pn].speed));
836                 break;
837         }
838         //x-=4;
839         y-=pip[0].map->tiles->tileHeight;
840         switch (player[pn].d)
841         {
842                 case 0:
843                         //up
844                         dire*=player[pn].d;
845                         y-=qq;
846                         by-=4;
847                 break;
848                 case 3:
849                         // right
850                         dire*=(player[pn].d-2);
851                         x+=qq;
852                         bx+=4;
853                 break;
854                 case 2:
855                 break;
856                 case 4:
857                         //down
858                         dire*=(player[pn].d-2);
859                         y+=qq;
860                         by+=4;
861                 break;
862                 case 1:
863                         //left
864                         dire*=(player[pn].d+2);
865                         x-=qq;
866                         bx-=4;
867                 break;
868         }
869
870 #ifdef SPRITE
871 #define FRAME1 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 32, dire, 16, 32, PLAYERBMPDATA);
872 #define FRAME2 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 16, dire, 16, 32, PLAYERBMPDATA);
873 #define FRAME3 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 0, dire, 16, 32,  PLAYERBMPDATA);
874 #define FRAME4 PBUFSFUN(pip[/*!*/(pip->video->p)].page, x, y, 16, dire, 16, 32, PLAYERBMPDATA);
875 #else
876 #define FRAME1 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, 2+dire);
877 #define FRAME2 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, 1+dire);
878 #define FRAME3 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, dire);
879 #define FRAME4 modexClearRegion(pip[/*!*/(pip->video->p)].page, x, y, 16, 32, 1+dire);
880 #endif
881         if(!pageflipflop)
882                 modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 36);
883         else{
884                 //copy old bg to page0
885                 //modexCopyPageRegion(pip[3].page, pip[0].page, bx, by, 0, 0,   20, 36);
886                 //update buffer
887                 //modexCopyPageRegion(pip[0].page, pip[3].page, 0, 0,   x, y,   20, 36);
888         }
889 //modexCopyPageRegion(page_t *dest, page_t *src, word sx, word sy, word dx, word dy, word width, word height);
890         //modexCopyPageRegion(pip[3].page, pip[!(pip->video->p)].page, x-4, y-4, 0, 128, 28, 36);
891         /*modexCopyPageRegion(pip[pip->video->p].page,
892  pip[!(pip->video->p)].page, x-4, y-4, x-4, y-4, 28, 36);*/
893 //      else modexCopyPageRegion(pip[1].page, pip[0].page, x-4, y-4, x-4, y-4, 28, 40);
894         switch(ls)
895         {
896                 case 1:
897                         FRAME1
898                 break;
899                 case 2:
900                         FRAME2
901                 break;
902                 case 3:
903                         FRAME3
904                 break;
905                 case 4:
906                         FRAME4
907                 break;
908         }
909 //      if(2>ls && ls>=1) { FRAME1 }else
910 //      if(3>ls && ls>=2) { FRAME2 }else
911 //      if(4>ls && ls>=3) { FRAME3 }else
912 //      if(5>ls && ls>=4) { FRAME4 }
913         //modexCopyPageRegion(pip[0].page, pip[3].page, 0, 0, x, y, 16, 32);
914         //printf("x=%d  y=%d    bx=%d           by=%d\n", x, y, bx, by);
915         pip->video->r=1;
916 }