OSDN Git Service

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